Results 1 to 8 of 8
  1. #1
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Activate option buttons with TAB (VBA Excel)

    Hi,

    I have set up a small userform. It has a Frame control and inside the frame I have 3 option buttons, one of which is the default option (with the little black dot). When I run the form, the default option button has the little black dot, but when I tab through the options, only the label gets selected....the little black dot stays on the first option. I need to have the black dot switch from one button to the other when I tab or use the arrow keys. Is this a property setting that I have not selected, or do I need to do this programatically??

    Tx
    Regards,
    Rudi

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Activate option buttons with TAB (VBA Excel)

    Hi,
    You would need to do this programmatically, but I would advise against it. This is not typical behaviour for Windows applications - generally you press the space bar to select an option - and it would mean that users could not tab through all the controls on your form but would have to use the mouse (unless they always wanted to select the third option!).
    If you did insist on it though, you can use the Enter event for the option button to set its value to True.
    HTH
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Activate option buttons with TAB (VBA Excel)

    Thats great Rory...TX
    I do agree....Tab is actually for cycling through groups of controls, where the arrows could be used to cycle between options in a frame.

    If you activate the Edit | Go to | Special dialog in Excel, you will see that TAB goes to the grouped options and the arrows chooses an option in the group. In VBA ' s userform, the Tab key simply jumps to the next option. I can use the on enter event of each option to activate it, but how will I get the tab key to jump to the next group event??

    Sorry for all the Q's
    TX

    PS: I forgot about the spacebar...that did effectively select the option button!! <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>
    Regards,
    Rudi

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Activate option buttons with TAB (VBA Excel)

    I would set the tab stop of the frame control to true, and the tab stop of each of the option buttons to false. Then use something like this:
    <pre>Private Sub Frame1_Enter()
    Select Case True
    Case OptionButton1
    OptionButton1.SetFocus
    Case OptionButton2
    OptionButton2.SetFocus
    Case OptionButton3
    OptionButton3.SetFocus
    End Select
    End Sub
    </pre>


    to set focus to the currently selected option when the frame gets the focus. If you then add code to the Enter event for each option, you can tab to the frame, then use the arrows to move up and down and pressing tab again will move to the next control, not the next option.
    HTH
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Activate option buttons with TAB (VBA Excel)

    Many TX Rory...
    Have one on me.... <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Regards,
    Rudi

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Activate option buttons with TAB (VBA Excel)

    Seeing as it's Friday, don't mind if I do! <img src=/S/grin.gif border=0 alt=grin width=15 height=15> (it will probably be a little darker than that one though!)
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Activate option buttons with TAB (VBA Excel)

    Then it'll be an ale! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Regards,
    Rudi

  8. #8
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Activate option buttons with TAB (VBA Excel)

    Specifically a Stout (like me!) or Porter. Technically, it's not black, as many people think, just very very very very dark red. <img src=/S/yum.gif border=0 alt=yum width=15 height=15>
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •