Using Enter to move to next field

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 IfEnd 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.


Share the Post: