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.

See also - an AI reverse image search platform

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist