Selecting Contents of Text Box

G

Guest

I am using Access 2002. I have this datasheet subform where my user enters
numeric data into a text box to populate the related field in the datasheet.
By default, whenever a new record is created, the value of the field is set
to 0.

Things work wonderful when the user enters data in one cell (text box) and
just tabs over to the next cell to enter in her data. This is because the 0
that is created by default when the new record is created is completely
highlighted when the she tabs over to it. She can then enter her new number
which writes over the 0.

Her complaint is that when she mouses over to the cell instead of tabbing
over to it, and puts the cursor in the text box, rather than highlight the 0
to write over it, the "I-beam" from the mouse simply sticks the cursor before
or after the 0, depending upon where she places it. The result is that she
has a 0 attached to the number she entered that she has to go back to and
delete.

I have tried setting up an input mask, but it doesn't work for a numeric
data type.
My question is: Is there some type of property I can set for the text box
control to always completely highlight the data when the mouse clicks on it,
much like the data is highlighted when you tab over to it?

Thanks
 
B

Brendan Reynolds

I originally tried this in the Enter and GotFocus events, but the selection
merely flickered briefly and returned to normal. Works in the MouseUp event,
though ...

Private Sub Text3_MouseUp(Button As Integer, Shift As Integer, X As Single,
Y As Single)

Me.Text3.SelStart = 0
Me.Text3.SelLength = Len(Me.Text3.Text & vbNullString)

End Sub

Of course, you know what will happen now, don't you? The user will complain
that when she enters, for example, 123 when she meant to enter 13, and she
places the cursor between the 2 and the 3 in order to backspace over the 2,
the entire text gets selected ...

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
G

Guest

Thanks,

The problem you described below was easily resolved by turning it into an if
statement, for me,

If Text3 = 0 Then
 

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