Enter to Tab

By | 2002-06-01

This code gives the “enter” key the same functionality as the “tab” key in a vb form. When the user presses the “enter” key, it moves the focus to the next control, based on the tab index order. Don’t forget to set the KeyPreview property of the form to True. (My thanks to Pennington. His TabToEnter2 code laid the foundation for this code.)

Original Author: K.Olayan

Assumptions

The KeyPreview event of the form must be set to true for the Form_KeyPress event to fire.

Code

'add this to your form's code
Private Sub Form_KeyPress(KeyAscii As Integer)

'catch both "Enter" keys on keyboard
If (KeyAscii = vbKeyReturn) Or (KeyAscii = vbKeySeparator) Then
  SendKeys "{tab}"
End If
End Sub

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.