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

Move on Enter

Status
Not open for further replies.

prprogrammer

Programmer
Jun 25, 2004
49
PR
Hi I have a form with couple of textboxes,,,I want to move the focus over textboxes with enter key like I do with Tab key...
 
Check out the KeyDown() event for the textbox... test if the key that was pressed is vbKeyReturn (the Enter key.)

Code:
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    If (KeyCode = vbKeyReturn) Then Text2.SetFocus
End Sub

Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
    If (KeyCode = vbKeyReturn) Then Text1.SetFocus
End Sub
 
prprogrammer,

For a more general solution try;

'only the KEY_RETURN,UP and DOWN Consts are used in the example but here are some others
Public Const KEY_PRIOR = &H21, KEY_NEXT = &H22
Public Const KEY_UP = &H26, KEY_DOWN = &H28
Public Const KEY_RETURN = &HD, KEY_ESCAPE = &H1B
Public Const KEY_HOME = &H24, KEY_END = &H23
Public Const KEY_LEFT = &H25, KEY_RIGHT = &H27
Public Const KEY_DELETE = &H2E, KEY_TAB = &H9, KEY_BACK = &H8

Sub SimulateKeys(ByVal KeyCode)

Select Case KeyCode
Case KEY_UP
SendKeys "+{TAB}"

Case KEY_DOWN, KEY_RETURN
SendKeys "{TAB}"
KeyCode = 0 'stops the beep when you press Return in a text box

End Select


End Sub



Private Sub Tb_KeyDown(KeyCode As Integer, Shift As Integer)

SimulateKeys KeyCode

End Sub

regards Hugh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top