selecting an entire field

  • Thread starter Thread starter Keith
  • Start date Start date
K

Keith

I have a form with lots of fields on it. The user only needs to input
either dates or numbers into some of the fields, depending on the entry
they are making.

I have tried to get the users to use the Tab key to move from field to
field but most of them still use the mouse. This caused the problem of
then clicking the wrong part of the field. For example if they click in
the middle of a date field they might leave the cursor in the middle and
not at the start of the entry. This is not a problem if you Tab to the
entry because the whole field is then highlighted.

Is there a way to make the whole field highlighted if the user simply
clicks on the field?

I am using Access 2000
 
It is frustrating to set up a form for easy keyboard navigation only to have
users stop and reach for the mouse every time. It slows down what should be
an efficient process. However, many people are unwilling to consider
changing how they have always done things, so we are left to deal with the
way things are.

I have tried to get the code below to work in the form's Got Focus event or
Enter event, but cannot figure out how. It must have something to do with
the order in which events fire. However, I can tell you how to place the
cursor at the beginning of a field. From a post I made yesterday, you could
use the following in the On Click event:

Me.ControlName.SelStart = 0

Or if you want to allow the user to click where wanted to edit existing
data:

If IsNull(Me.ControlName) Then
Me.ControlName.SelStart = 0
End If
 
In the control's OnClick event, put this code:

Me.ControlName.SelStart = 0
Me.ControlName.SelLength = Len(Me.ControlName)

HTH,
Barry
 
That would make it necessary to use the arrow keys to edit an existing
record. Users who can't remember to use the tab key will surely be
frustrated when they find they can't click to position the cursor within a
field.
 
The only work-around is to allow them to double-click to select within
the text. You could declare a module-level variable, set it in the
Click event, and then set the SelStart in the Double-click event.
Something like this:

'At the top of the module
Dim m_intSelStart As Integer

'In the OnClick event:
m_intSelStart=Me.ControlName.SelStart
Me.ControlName.SelStart = 0
Me.ControlName.SelLength = Len(Me.ControlName)

'In the DblClick event:
Me.ControlName.SelStart = m_intSelStart
Me.ControlName.SelLength = 0
Cancel = True

This way the default behavior is still that it selects the entire
field, but they can override it.
 
From where does m_intSelStart get its value in the Double Click event? You
declared the variable in the module's general declarations (if I am using
the correct terminology), but never defined it that I can see.
In any case, while it is probably possible to have all of the text selected
upon clicking in the text box, and to override that by using the arrow keys,
or avoid it completely by double-clicking instead of single clicking, I
don't see how any of that helps the user who can't remember to use the Tab
key.
 
I guess I'm not sure what your objective is here. Do you want to
completely prevent them from using the mouse to click in a field? That
can be done.

But I thought you wanted to give users who clicked with the mouse the
same highlight results as when they tab into the control. This will do
the trick.

What are you looking for?
 
If you'll check this thread you'll see that I am the person who replied, not
the person who asked the question in the first place. The person who
originally asked the question did not post again in this thread. I just
wanted to point out that using the click event to highlight the entire field
means that users would need to find another way (such as arrow keys) to move
the cursor around in the field to edit it. Any attempt to use the mouse to
position the cursor would result in the entire field being selected. If
users are uncomfortable with the Tab key they will probably be even more
uncomfortable with arrow keys. That was my point.
The most likely situation in which clicking in the middle would be an issue
is with an input mask, in which case it is possible to click in the middle
of a phone number or something like that, even if the field contains no
data. My original suggestion included a way of running the code only if the
field is empty. My most recent question was because I couldn't figure out
how the general variable was supposed to work in the posting that included
the double-click event.
 
Sorry. I didn't notice that you weren't the original poster. I guess he
lost interest.

The m_intSelStart variable is set in the OnClick event, which always
fires before the double-click event.
 
I didn't know that about the Double Click always firing before the click
event. That may save me from some aggravation in the future. So even
though the original poster has departed, I have picked up something useful
from this conversation.
 
Back
Top