Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing Behavior of the <Enter Key? DCSwearingen Excel Discussion (Misc queries) 4 April 25th 06 03:23 PM
UserForms bennyob Excel Discussion (Misc queries) 4 November 7th 05 01:58 PM
Userforms nath Excel Programming 1 May 20th 04 04:53 PM
Userforms Gary[_8_] Excel Programming 1 August 18th 03 03:26 PM
Userforms Henry[_4_] Excel Programming 0 August 9th 03 11:37 PM


All times are GMT +1. The time now is 04:24 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"