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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

highlight text in textbox on GOTFOCUS?? 2

Status
Not open for further replies.

jmorlock

Programmer
Apr 25, 2003
46
0
0
US
When a text box gets focus how do you highlight the text?
I was thinkin you could use the len() command to find the length of the text and then the selstart or sellength.I cant seem to get it to work, does anyone have some hints?
 
With the DB Window visible. From the Menu select Tools->> Options, select the Keyboard Tab, under "Behaviour Entering Fields" select "Select Entire Field".

Best of Luck

Bill
 
Bills method above sets this selection behaviour as the default whenever a control on a form gets the focus. If you want to select the entire contents of a control where its not already selected, just press the F2 key when the control has the focus. Pressing it again, deselects the contents and puts the cursor at the end of the content. I find that its good to teach the users about these sorts of keys anyway.



Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Bill's method works if you are tabbing into the field, but if you want to highlight it when you click on it, then for that text box's On_Click event,

Code:
Private Sub txtYourTextBox_Click()
    SendKeys "{F2}"
End Sub[code]

Good luck,
Spaniard.
 
Hi Steve101 and Spaniard,

I find it very interesting seeing other members' suggesting other methods besides my own. I had't thought of F2 so both deserve being marked as helpful.

Keep the good ideas coming,

Bill
 
Hi Bill,

You are too kind - I am only glad to help after all the help I have received from other members...

Thanks,
Spaniard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top