I have developed a global subroutine that will highlight the text of the active control of the active form.
The routine is simple:
Sub Highlight()
On Error Resume Next
Dim FRM1 As Form
Set FRM1 = Screen.ActiveForm
FRM1.ActiveControl.SelStart = 0
FRM1.ActiveControl.SelLength = Len(FRM1.ActiveControl)
End Sub
Create a form object by first dimensioning it and setting it to the active form. Next, select the text of the form’s active control starting at the left most character to the end of the text.
Use this in the got_focus method of any control that allows text entry such as a text box or a combo box.
Private Sub Text1_GotFocus ()
Call Highlight
End Sub
That’s it! One subroutine call does it all. I put this routine in a global module so all my forms have access to it.
Tip Submitted By: Marc Mueller
Discover more from dotNetTips.com
Subscribe to get the latest posts sent to your email.
