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

Enter Key

Status
Not open for further replies.

takeover

Programmer
Jul 9, 2003
52
US
Hi Gurus,

I am new to VB. Is there a way to write an even procedure in VB. The thing I need to achieve is, I have some text boxes in a form and when I enter a value in one text box and press enter key, I need to accept the value in a variable and the cursor should go to the next text box. How could I achieve this?

takeover
 
Try this .....


Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then Text2.SetFocus
End Sub
 
I forgot the variable part ....

Public TextData

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then Text2.SetFocus
Textdata = Text1.text
End Sub
 
Hi,

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'Be sure to have the form's keypreview property set to true.
If KeyCode = vbKeyReturn Then SendKeys ("{Tab}")
End Sub

Have a good one!
BK
 
And to get rid of the Beep use the KeyPress event instead, and a slight addition to BlackKnight's code wxample:

Private Sub Text_KeyPress(KeyCode As Integer, Shift As Integer)
If KeyAscii = vbKeyReturn Then
SendKeys ("{Tab}")
KeyAscii = 0
End If
End Sub

This, (all of the above examples) will conflict with things like Multi-Line text boxes, so you should check the control name and exempt these from the "override"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top