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

Move the focus to the next control after "Enter" 2

Status
Not open for further replies.

seaport

MIS
Jan 5, 2000
923
US
I am new to VB. The question is simple.

How to move the focus to the next textbox after I enter "Enter" key at the first textbox?

Now when I enter "Enter" in a textbox, the cursor just stays there.

Thanks in advance.

Seaport

 
use the .setfocus method of the control you'd like to move to in the keypress method of the control that is receiving the keypress. Check keyascii for the value 13.

Further..the annoying beep can be supressed by setting keyascii=0 once you've determined the value of it.

Private Sub Control1_KeyPress(KeyAscii As Integer)
'move to next control
If KeyAscii = 13 Then 'enter key was pressed
KeyAscii = 0 'supress beep
Control2.SetFocus
End If
End If
End Sub

Happy Coding :)
 
These work without knowing the next control to TAB to.
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
KeyCode = 0
Text1.Enabled = False
Text1.Enabled = True
End If
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
KeyCode = 0
sendkeys "{tab}"
End If
End Sub Compare Code (Text)
Generate Sort in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top