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!

control focus question

Status
Not open for further replies.

bobsg

Programmer
Jul 3, 2001
12
0
0
US
When a control gets the focus the contents are highlighted and the user is in the replace mode. This seems to work if you tab between controls or use code to move the focus to a control. When you use the mouse and click in a control the focus moves to that control but you are not in the replace mode and have to delete the contents of the control before typing in order to replace what is in the control. Is there a way when the mouse is used to move the focus to a control that that the user be in the replace mode.

Thanks,
Bob Gouveia
bob@cgm-cpa.com
 
You could try this:


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


This just basically highlights all the text in the text box whenever it receives focus.

Hope this is what you are looking for. :)
 
Sorry, that does not quite work. I was thinking in VB and it looks like it does not work the same way.
 
Thanks Jitter for responding. At least you helped me better word what it is I'm trying to do. I would like to select all the text in a control when the focus is moved to the control with a mouse click. I hope there is someone out there who can give me a suggestion about this issue.


Thanks,
Bob Gouveia
 
Bob, the following click event selects all text in the field when the user clicks on it.
Code:
Private Sub JobTitle_Click()
JobTitle.SelStart = 0
SendKeys "(+{end})", True
End Sub

You could try iyt on the GotFocus, I suppose.

I want to point out that there is a program I have to work with on a regular basis that does this and it's very annoying when I want to edit instead of overwrite.

By default, selecting the name (the label) of a field in Access selects all text for overwriting and I've gotten pretty used to that.

Of course, free advice is worth what it cost you.

HTH


John
 
Thanks John for the response. In this case the fields involved are one character fields that the user will be changing so if the user does click in the control he will be able to change the contents with a single key press. I am using a continous form so that the user can see multiple records. I appreciate the help.

Bob Gouveia
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top