"tab" or "enter" keystroke

crowegreg

Registered User.
Local time
Today, 15:32
Joined
Feb 28, 2011
Messages
108
Is their any way to determine if the user pressed the "tab" key or the "enter" key? I'd like to preform different events after determining which keystroke the user performed.
 
You can use the Key Down or Key Press events of the control you wish to trap or the form. I think the code is 9 for tab, can't remember.

If you're going to trap it at form level, you will need to set the KeyPreiew property of the form to Yes.
 
Can you provide a little more detail to your solution. Thanks!!
 
Let's say you have a texbox called Textbox1 and you want to trap when a user Tabs from that textbox, you would do this in the Key Press event or the Key Down event of the textbox. Look in the property sheet of the textbox under the "Event" tab and you will these events I've mentioned.

For the Key Down event, put the following line of code:
Code:
    MsgBox "KeyCode: " & KeyCode
Then open your form in design view, put the cursor inside the textbox and tab out.
 

Users who are viewing this thread

Back
Top Bottom