Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlight Text Box on GotFocus Event

Status
Not open for further replies.

simran1

Programmer
Apr 23, 2002
82
US
Hi,

How do i use highlight the contents of the textbox, when on getfocus event?
I tried using SelStart and SelLenght, but am unable to get the results.
Thans for the time taken to help.
 
Try this code:

txtField1.SelStart = 0
txtField1.SelLength = Len(txtField1)
 
Hi,

Thank you so much. I missed out putting in the length of the field.
 
You can also put it in you form load statement to do this for every text box.

Options Explicit
dim ctltext as control

For Each ctlText In Controls
If TypeOf ctlText Is TextBox Then
If ctlText.SelStart = 0 Then
ctlText.SelLength = Len(ctlText)
End If
End If
Next ctlText
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top