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!

Select all text when set focus on text box

Status
Not open for further replies.

thromada

MIS
May 10, 2004
30
US
Hi all,
I haven't found in the threads yet how to do this exactly. Using Access 2003, if you enter text in a text field, then loose focus by doing some other code to say, display some records in a list box, then come back to the original text field, how do you get it to select all the text that's already in the text field?

Most threads just say "check out SelText". Well, I've tried multiple combinations of all the Sel properties. And multple combinations of placing it in gotfocus, on enter, before update, etc.

What's the definitive code?

Thanks.




I want to enter text in a text field, do some other code to display records that match the text field, then go back to the text field and highlight all the text so you can see what you just entered, but so when you start typing in that field it erases what was ther
 
In the GotFocus event procedure:
Me![text box].SelStart = 0
Me![text box].SelLength = Len(Me![text box])

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV,
I've tried that and upon the very first time of moving to that text field when first running the form, I get "Run-time error '13': Type mismatch. If I leave the Me! off the front of the field name, I get "Invalid use of Null".

Could setting focus be messing this up? After I do other things and want to come back to the original text field, if I use <field1>.SetFocus, it doesn't go to the field. If I use:

<field1>.Visible = True
<field1>.SetFocus

It still doesn't go to the field. If I use:

<field2>.SetFocus
<field1>.SetFocus

Then it sets focus correctly. I have to focus on another field, then back to the one I want to have focus.

I had tried this in the past and out of frustration, just made another field on the form that shows the last text entered, and cleared the original input field. I was hoping to see what I might be doing wrong.

Thanks.
 
In the GotFocus event procedure:
Me![text box].SelStart = 0
Me![text box].SelLength = Len(Me![text box][!] & ""[/!])

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks, that & "" fixed the error messages. But the selection still doesn't occur. I can see all the text get selected for an instant, then it's unselected and the cursor is at the beginning of the field.

I don't think I'm building the form wrong. Think it could be the setfocus?
 
I know if you go into tools/options there is a tickbox for selection, ie partial or fully enclosed in the forms/reports tab. But I think that will affect everything in your form. Trouble is you can come unstuck when text is highlighted, one unwanted keypress and the textbox is emptied.
 
What is your actual code and in which event handler ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
As to the

<field2>.SetFocus
<field1>.SetFocus

working, if this is setting focus on <field1>, where

<field1>.SetFocus

alone didn't do it, then the problem was that <field1> already had focus!

Do you have a sub named field1_Enter() and if so what code is in it?

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
It had the focus. I got it. Thanks all for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top