-
I'd like to be able to detect if the tab key is pressed and perform my own event instead of going to the next object in the tab index.
I've tried using the keypress event -- I don't see an "ascii 9" or a "vbKeyTab"
The KeyUp and KeyDown events say specifically that they're not triggered for a tab event...
Any ideas?
Thanks
-
vbTab
vbTab Chr(9) Horizontal tab.
Hope this helps..
-
Andrew (good name my man), there is a vbKeyTab constant. I checked it to be sure in the keypress event of a textbox and it worked, like this:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyTab Then
MsgBox "THIS IS A TAB!"
Else
MsgBox "THIS IS NOT A TAB!"
End If
End Sub
Whatever control you are using should recognize the vbKeyTab constant. For the second part of your question, do this:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyTab Then
KeyAscii = 0
Text1.SetFocus
'enter your subroutine or process here
End If
End Sub
-
Unfortunately here is how the Tab key works. If there is only one control on a form with TabStop = True, the Tab key will be recognized, but if there is more than one it won't be. What you need to do is in the form's Load event, store the TabStop values for all the controls that you are interested in, and then in the GotFocus even of each control set the TabStop property of all other controls to False, and then set them back to their originally stored vales in the LostFocus event.