-
Key press - event
I have a strange problem.
I tried to test the "Key press - event" for several objects:
commandButton,label,textbox...
The problem is that the event returned (by msgbox) the KeyAscii
each time when I clicked on the keyboard, except from the tab key.
Why?
Thank you
-
Does this work for you?
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyTab Then MsgBox "Tab pressed"
End Sub
Private Sub Form_Load()
Me.KeyPreview = True
End Sub
-
Because that is that the KeyPress event returns. It returns the ASCII code for the key.
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
To convert the ASCII code to something useful:
Code:
MsgBox Chr(KeyAscii)
The TAB key should be 9. Remember to set the Form's KeyPreview property to True.
-
ok, a label doesn't have a keypress event, and the reason keypress isn't fired by tab is because it is setting the focus to some other control in the tabindex before it can fire for the current control and I have no clue why it doesn't fire on the control that it sets focus to though.