Selecting OptionButtons

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
Say for example there are 2 form optbuttons in a frame; is it possible to
tab to the required option and 'click' the button using the Enter key? If so
how?

My form has a number of optionbuttons amongst textboxes and it is becoming
tedious to keep reaching for the mouse to make a choice or confirm something.
It would be great to just use the keyboard as far as possible.

T.I.A

Geoff
 
Probably not an issue but ensure that the option buttons properties are
correct. Tab Stop it True and Tab index is in the correct order...
 
Spacebar works fine when focus is on a frame which has an Exit event with
Cancel = True clause. Thank you:):)

But in another part of the form I have 4 pairs of txtboxes, each pair
representing hours and minutes. After a correct entry, I move the focus by
SetFocus from one txtbox to the next. The first 3 pairs are summed after
entering minutes in the 3rd pair(box 6) and the total is shown in pair 4.

To assist data entry in the 3rd pair I have an optionbutton which reveals a
'totaliser' for that pair only. Using the mouse I can click for this
function before data is entered into the 3rd pair or just enter directly.

Here is the problem with the Spacebar solution.
Despite using tabstop=true and tab order etc I cannot navigate to this
option button to use the Spacebar, I assume because of the coded tabbing to
the 4th pair of boxes. Does this make sense?

I wondered if i should be using Application.OnKey somehow?

Geoff
 
Geoff,

Do you have an accelerator key set on the option button?

Enter a character from the button caption in the "Accelerator"
property in the VBE.
Then use Alt + (that character) to activate the button.

Regards,
Jim Cone
San Francisco, USA


Spacebar works fine when focus is on a frame which has an Exit event with
Cancel = True clause. Thank you:):)

But in another part of the form I have 4 pairs of txtboxes, each pair
representing hours and minutes. After a correct entry, I move the focus by
SetFocus from one txtbox to the next. The first 3 pairs are summed after
entering minutes in the 3rd pair(box 6) and the total is shown in pair 4.

To assist data entry in the 3rd pair I have an optionbutton which reveals a
'totaliser' for that pair only. Using the mouse I can click for this
function before data is entered into the 3rd pair or just enter directly.

Here is the problem with the Spacebar solution.
Despite using tabstop=true and tab order etc I cannot navigate to this
option button to use the Spacebar, I assume because of the coded tabbing to
the 4th pair of boxes. Does this make sense?

I wondered if i should be using Application.OnKey somehow?

Geoff
 
Jim
Thanks for the reply.
That works fine in this layout. I have a number of frames to test but up to
now it has performed as needed. Because of the number of buttons and
similarity of captions i guess i will have to be inventive with the key
letter.

Accelerator plus spacebar plus tab order should give me plenty options
(sorry - couldn't resist that) to play with.

Thanks to all for their contribution.

Geoff
 
On further testing of Accelerator I have a problem.

I use a label to name an optbutton rather than its caption. When I set an
accelerator on the optbutton the function works fine. If I set an
accelerator on the label it does not, yet according to VB Help: 'If the
accelerator applies to a Label, the control following the Label in the tab
order, rather than the Label itself, receives the focus.'

Any further suggestions other than use the optbutton caption?

Geoff
 
Geoff,
As Anne said: "spacebar"
Jim Cone


On further testing of Accelerator I have a problem.

I use a label to name an optbutton rather than its caption. When I set an
accelerator on the optbutton the function works fine. If I set an
accelerator on the label it does not, yet according to VB Help: 'If the
accelerator applies to a Label, the control following the Label in the tab
order, rather than the Label itself, receives the focus.'

Any further suggestions other than use the optbutton caption?

Geoff
 
Hi,
what about something like this:

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As
Long) As Integer

Private Sub OptionButton1_Enter()
If GetAsyncKeyState(vbKeyMenu) And &H8000 Then OptionButton1.Value =
True
End Sub

Private Sub OptionButton1_KeyDown(ByVal KeyCode As
MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = Asc(UCase(Label1.Accelerator)) And Shift = 4 Then
OptionButton1.Value = True
End Sub

Private Sub OptionButton2_Enter()
If GetAsyncKeyState(vbKeyMenu) And &H8000 Then OptionButton2.Value =
True
End Sub

Private Sub OptionButton2_KeyDown(ByVal KeyCode As
MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = Asc(UCase(Label2.Accelerator)) And Shift = 4 Then
OptionButton2.Value = True
End Sub
 
Hi okaizawa
Thats cool! Prime objective reached.

1. I can maintain the labels, which in a number of cases have to be above
the optbutton (hence no button captions).
2. It saves a key depression in operation, which with a detailed data entry
form saves time and patience - every little bit helps.

Again thanks to all for their help. Two solutions for one problem can't be
bad.

Geoff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top