devxlogo

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.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Five Early Architecture Decisions That Quietly Get Expensive

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.