VBNotebook Home | Functions | VB Notebook Select Text Upon Entry
This routine allows you to select text when a user enters a text box or other controls with a SelStart and SelLength properties. By having the routine separate, you could add additional code to it for various purposes. You could also put this same code in each control's GotFocus event.
First, here's the generic routine...
__________________________________________________________________________________________
Public Sub SelectText(ByVal txtBox As Control)
On Error Resume Next
With txtBox
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub
__________________________________________________________________________________________
...and here's an example of calling the routine in the GotFocus event of a
text box...
__________________________________________________________________________________________
Private Sub txtData_GotFocus(Index As Integer)
SelectText txtData(Index)
End Sub
__________________________________________________________________________________________
Copyright 2000-2005, J. Frank Carr