Auto-highlight textbox data?

D

Dennis

In Access 2003, I need to automatically highlight the contents of several
textboxes when a user TABs into them. This is so the person doesn't have to
hit the backspace or delete keys to remove existing data which might be
present, but can just start typing, and the data will replace whatever was
there. I know this is possible; I even read it once on the newsgroup here,
but I don't recall the method and can't find it using SEARCH.

Any assistance would be most appreciated. If possible, I'd like it to be a
property setting for the affected textbox controls.

Thanks!!
 
A

Al Campagna

Dennis,
Whenever you Tab into a text control with an existing value, the whole
value is selected. That is a built in Access function, and does just what
you're looking for.
So, I'm a bit confooosed by that. Maybe you mean... "when a user clicks
the mouse into a text control."

There are three methods for selecting the contents of a text control...
1. Tabbing into the field. Always navigate with the Tab....
2. If the text Control has an associated label, mouse clicking the
Label highlights the contents of the text control... ready for "typeover."
3. Double-clicking a text control with the mouse will select all
the contents.

If you must "code" for this...

Private Sub YourFieldName_Click()
YourFieldName.SelStart = 0
YourFieldName.SelLength = Len(YourFieldName)
End Sub

When one mouse click occurs in the field, the entire field value is
selected.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
L

Linq Adams via AccessMonster.com

Actually, you have to goto Tools - Options - Keyboard and set the Behavior
entering field to "Select entire field" for that to happen! You can also set
it to go to the beginning of field or end of field.
 
D

Dennis

Actually, I think that selecting the entire text is optional, because in this
application, when I tab into the field, the cursor is placed to the left pf
the existing data, and nothing is highlighted. I am hoping that there is a
Proerty setting for each textbox control that will default to actually DO the
highlighting when tabbing in.

BTW, thanks for that code snip; I'll use that if all else fails. It's just
that I have about 20 of these fields, and I'd rather do it as a Property
setting if possible. (This is an UNBOUND form and controls, FYI)

Dennis
 
M

Marshall Barton

Dennis said:
In Access 2003, I need to automatically highlight the contents of several
textboxes when a user TABs into them. This is so the person doesn't have to
hit the backspace or delete keys to remove existing data which might be
present, but can just start typing, and the data will replace whatever was
there. I know this is possible; I even read it once on the newsgroup here,
but I don't recall the method and can't find it using SEARCH.

Any assistance would be most appreciated. If possible, I'd like it to be a
property setting for the affected textbox controls.


You can use code in the text box's Enter event procedure:

Me.sometextbox.SelStart = 0
Me.sometextbox.SelLength = Nz(Len(Me.sometextbox), 0)
 
M

Marshall Barton

Linq said:
Actually, you have to goto Tools - Options - Keyboard and set the Behavior
entering field to "Select entire field" for that to happen! You can also set
it to go to the beginning of field or end of field.


The problem with that setting is that it applies to every
text/combo box in every form.
 
L

Linq Adams via AccessMonster.com

I've always felt that setting the Default to hilite on enter kind of
dangerous. To easy to wipe out an important field/primary key! The code Al
gave is the usual way of handling this.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top