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

How can I select all the text in a

Status
Not open for further replies.
Oct 24, 2002
512
US
How can I select all the text in a text box when the user clicks in the text box? I'm using this text box to filter records based on whatever the user types. There's always data in the control (I have it set to equal another field on the form.) The way it is now, the user has to manually select all the text before they can type in something else.

Thanks.
Ann
 
Hi

There is an option (in Tools\Options) to change the select behaviour when a control gets the focus, is that what you are looking for? Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
That doesn't work when the user clicks in the text box. Anyway, I'm not really looking to change any default behavior. I was hoping there would be some code I could use behind a given text box. Any other ideas?
Ann
 
If you want the box cleared when the user clicks on it....couldn't you use the OnClick event and just clear the box???

The following worked fine for me:




Private Sub Text0_Click()

Me![Text0] = ""

End Sub Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III, MCSA, MCP, Network+, A+
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Robert, you're suggestion does clear the text box which would suit me just fine except that for some reason my AfterUpdate event doesn't fire now. Any thoughts?

Private Sub Text86_AfterUpdate()
On Error GoTo HandleErr

ExitHandleErr:
Exit Sub

HandleErr:
MsgBox "Error #" & Err.Number & vbCrLf & vbCrLf _
& Err.Description, vbOKOnly, "TBC 401(k) Program"
Resume ExitHandleErr

DoCmd.OpenForm "frmEmployeeData", acNormal, , "[EmployeeName]like '*" & [Text86] & "*'"


End Sub
 
Hi

After Update does not fire if you set value in code

you could force it

Private Sub Text0_Click()

Me![Text0] = ""
Text0_AfterUpdate

End Sub

In VB6 it is possible to set the selected text, I would need to time to look to see if you can do it in VBA

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
KenReay,

Good suggestion! Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III, MCSA, MCP, Network+, A+
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Hi

Yes you can set the selected text as I suspected example

Private Sub Form_Load()
Text0.Value = "ABCDEFGHIJKLMNOPQ"
Text0.SetFocus
Text0.SelStart = 3
Text0.SelLength = 5

End Sub

causes DEFGH to be selected Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Ken, I tried forcing the AfterUpdate event as you suggested but it doesn't work for me. I'm going to try your other suggestion next.

Thank you both for the help.

Ann
 
I decided to go with a cmdRemoveFilter button which, when clicked, clears (sets to null) the values in all three text boxes that I use for filtering. Everything is working nicely now.

Thanks to both of you for educating me further!

Ann
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top