Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: VB4,VB5,VB6
Expertise: beginner
Sep 8, 2001



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Using Enter to move to next field

Most MsDos programs used the Enter key to move from one field to the next one. You can easily simulate this behavior by setting the form's KeyPreview property to True and writing this code in the Form_KeyPress event:

Sub Form_KeyPress (KeyAscii As Integer)
  If KeyAscii = 13 Then
    If TypeOf ActiveControl Is TextBox Then
      SendKeys "{TAB}"
      KeyAscii = 0
    End If
  End If
End Sub
This technique works only if there is no command button on the form with its Default property set to True, because in that case the Form_KeyPress would not trap the Enter key.
Francesco Balena
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date