About   -   Contact   -   Purchase   -   Search   -   What's New

Auto-Selecting Text
This handy routine automatically sets the focus and highlights text in a textbox. Then as the user types, the text is automatically overwritten. Possible uses are:
  • to direct users to invalid inputs after a validation routine
  • on an input form with a text box, an OK button (default enabled) and a Cancel button (cancel enabled) for repeated data entry, without continually reaching for the mouse between each entry.

To make a TextBox automatically select its text use the SelStart and SelLength commands as follows:

Private Sub cmdAutoHighLight_Click()
	Text1.SelStart = 0
	Text1.SelLength = Len(Text1.Text)
End Sub

Top of Page

Legal Notice

Ken Howe 2011