Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Enter Key behavior with Userforms
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Enter Key behavior with Userforms
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" wrote in message ... 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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Enter Key behavior with Userforms
Troy,
Thanks. Works great. I was missing the "Throw Away the Enter Keystroke" piece. I really appreciate your help. "TroyW" wrote: 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" wrote in message ... 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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Enter Key behavior with Userforms
Your welcome. -- Troy
"Lance" wrote in message ... Troy, Thanks. Works great. I was missing the "Throw Away the Enter Keystroke" piece. I really appreciate your help. "TroyW" wrote: 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" wrote in message ... 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Changing Behavior of the <Enter Key? | Excel Discussion (Misc queries) | |||
UserForms | Excel Discussion (Misc queries) | |||
Userforms | Excel Programming | |||
Userforms | Excel Programming | |||
Userforms | Excel Programming |