Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How-to catch the 'Tab' key from the Keyboard?

Status
Not open for further replies.

rmahawaii

Programmer
Oct 21, 2002
29
HK
Hello, I tried using KeyUp, KeyDown, and KeyPressed, but none will catch the key 'Tab' when I pressed the keyboard. Why event I should use to catch the user entered this key? Thanks.
 
in the KeyDown event write the following:
msgbox KeyCode

run the program, give focus to the text control (using mouse) and press tab, that will give the code for tab whci u can later use to capture,

or u can use vbKeyTab
 
I use the key tab in the axcStringField. The 'Tab' key didn't trigger the KeyDown, KeyUp, or KeyPress. Therefore, i can't compared with vbKeyTab. Other keys like the 'Enter' key will trigger the KeyPress event.
 

For what reason do you need to capturn the Tab key? [/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Cause I have a program that needs to check the text the user entered while they are inputing the form. Some user will press enter, others may use the tab to move to the next block.
 

The use the TextBox_Validate event.
If the text fails validation (isn't what you want it to be], then just set the Cancel to True. This will keep the focus on the control. (Assumming that the next control in the Tab order has the CauseValidation property set to True):

Private Sub TextBox1_Validate(Cancel As Boolean)
If TextBox1.Text <> &quot;abc&quot; Then
Cancel = True
Exit Sub
End If
End Sub [/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top