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

Making ENTER key behave like the TAB key... 1

Status
Not open for further replies.

mhendo59

Programmer
Jan 18, 2000
5
0
0
US
I am writing a program which consists of several text boxes. I have the tab stops set where you can tab from one text box to another.

I am trying to set the ENTER key to behave in the same way as the TAB key but I'm not quit sure how to go about this. I figure I need the ASCII character for the ENTER key equal to the tab key but that's the extent of it.

Any help is qreatly appreciated.

-Hendo
 
Put this code on KeyDown event of text box :

If KeyCode = vbKeyReturn Then SendKeys "{Tab}"
 
Thanks Oneshadow,

That did the trick!

-Hendo
 
Salut tt le monde
SVP J ai besoin d'un exemple d'utilisation de l'objet Onglet dans un programme VB5
Merci
 
a better way then SenKeys (and No Beeps ) :

Public Const WM_KEYDOWN = &H100
Public Declare Function PostMessage Lib "User32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Sub TabOnEnter(KeyAscii As Integer)

On Error Resume Next
If KeyAscii = vbKeyReturn Then
If TypeOf Screen.ActiveControl Is TextBox Then
If Screen.ActiveControl.MultiLine Then Exit Sub
End If
KeyAscii = 0
PostMessage Screen.ActiveControl.hwnd, WM_KEYDOWN, vbKeyTab, 0
End If
End Sub

In The keyPress of a control type :

TabOnEnter KeyAscii

Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX
Source CodeBook for the programmer
 
Or you could do this (a variation on Eric's method):

Sub TabOnEnter(KeyAscii As Integer)
On Error Resume Next
If KeyAscii = vbKeyReturn Then
If TypeOf Screen.ActiveControl Is TextBox Then
If Screen.ActiveControl.MultiLine Then Exit Sub
End If
KeyAscii = 9 ' tab
End If
End Sub

In The keyPress of a control type :

TabOnEnter KeyAscii
Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top