Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
When you tab from one text box or memo field to another in a form, the text in the control is highlighted. This makes it easy for users to accidentally delete the text by pressing a key. By using a few lines of code, you can move the insertion point to the first position in the text box, minimizing the risk of accidentally deleting the text.
To do this, create a procedure for the text box's GotFocus event. In the GotFocus event procedure, set the SelLength property of the text box to its SelStart property.
The following example illustrates how to do this for a text box named txtFirstName.
Private Sub txtFirstName_GotFocus()
Me.txtFirstName.SelLength = Me.txtFirstName.SelStart
End Sub
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.