Enter Key behavior with Userforms

G

Guest

How do I make the enter key not tab to the next control in the tab order? I want to be able to Tab from control to control on my userform using the TAB key. However, when the user presses the ENTER key, I want to run some code and stay at that control. Any suggestions? The enter key by default is tabbing to the next control and I have not found any property of the form to turn this off.
Thanks in advance
 
T

TroyW

Lance,

Here is an example of trapping the "Enter" keystroke using the KeyDown event
of a TextBox control. The logic is to check each keystroke inputted by the
user in the textbox control and if it equals the Enter key, throw away the
keystroke (keeping it will cause a tab to occur), and then call your other
subroutine.

Troy

Private Sub TextBox1_KeyDown( _
ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)

'''Trap the Enter key.
If KeyCode = 13 Then
'''Throw away the Enter keystroke.
KeyCode = 0
'''Call your subroutine here...
'''
End If
End Sub


Lance said:
How do I make the enter key not tab to the next control in the tab order?
I want to be able to Tab from control to control on my userform using the
TAB key. However, when the user presses the ENTER key, I want to run some
code and stay at that control. Any suggestions? The enter key by default
is tabbing to the next control and I have not found any property of the form
to turn this off.
 
G

Guest

Troy,
Thanks. Works great. I was missing the "Throw Away the Enter Keystroke" piece. I really appreciate your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top