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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I detect the key press "Tab" in a textbox?

Status
Not open for further replies.

RSX02

Programmer
May 15, 2003
467
0
0
CA
Hi
I tried to detect the Tab key with the keypress event (keyascii) and the keyup event (keycode) but it doesnt' detect it.
How can I see that this key was pressed.
I don't want to use the lost focus event.
Thanks in avance
 
You will need to set the forms keypreview property to true and set the tabstop property of all controls to false.

Why are you trying to catch the tab key? If it is to check if entered data is valid then try using the validate event. It is the last event fired when the control loses focus and will allow you to cancel (set cancel =true) the validation and have that control retain focus. See thread222-482338.

Take Care,

zemp

"Show me someone with both feet on the ground and I will show you someone who can't put their pants on."
 
it's because the user can navigate in the form with the tab key. The lost focus is not the event that i'm locking for because I don't want to do my search when he or she lost the focus on the field but when he or she hit enter or the tab key.

Thanks in advance
 
Well, from what you say, it sure looks like the Validate event, as advised by zemp, is a good candidate for this.
 
I don't know if this will help but here is some code I use to check for the "enter" key should only need to change a little for tab.
This is in the keypress event
If KeyAscii = 13 Then
KeyAscii = 0
SendKeys "{tab}"
End If
 
This worked for me....

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
MsgBox "Perform your action here!"
End If
End Sub

But the Validate Event would be more suitable (as suggested)
 
Unfortunately, LPlates, the KeyPress solution will only work if there is no other control on the form that can receive focus.
 
Thats funny! Yes you know what I did, opened a project and added one control to the form!

Solution: Delete all other controls.. HA HA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top