I have two option buttons, I wish to toggle between them every time the space bar is hit how is this done ?
Printable View
I have two option buttons, I wish to toggle between them every time the space bar is hit how is this done ?
Capture the keyboard_event and if the ASCii value of the key pressed is equal to the value for space bar, enable/disable the appropriate button.
How do you capture a keyboard event ?
Don't know why I can't get this to work for the space bar (ascii value = 32), but it works just fine for the Enter key (ascii value = 13) and just about any other key BUT the spacebar.
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Option1.Value = True Then
Option1.Value = Not Option1.Value
Option2.Value = Not Option2.Value
Else
Option2.Value = Not Option2.Value
Option1.Value = Not Option1.Value
End If
First of all set KeyPreview property of form to true. Then use this code:
private Sub Form_KeyDown(KeyCode as Integer, Shift as Integer)
If KeyCode = 32 then KeyCode = 13
If KeyCode = 13 then
If Option1 then
Option2 = Not Option2
else
Option1 = Not Option1
End If
End If
End Sub
Vlad