Select entire field on click

G

Guest

When editing formatted date fields, users are constantly frustrated at the
fact that Access places the cursor in the actual position where the click
occurred (imagine that!) instead of at the left (or alternatively, selecting
the entire field). How does one force the cursor to the leftmost character or
force full field selection on the Click event?
 
S

Steve Schapel

Brian,

On the Click event of the textbox, try code like this...

With Me.MyDateControl
.SelStart = 0
.SelLength = Len(.Text)
End With
 
G

Guest

Thanks. I know that the next complaint I will have from the users is that now
they have no way to highlight just part of the field for editing (I recall
something about wanting to have their cake and eat it, too....)
 
M

MacDermott

You could use the Enter event, instead of Click.
That way, the automatic selection will happen the first time they enter the
control, but subsequent mouse-action in the field will be respected.
 
G

Guest

That sounded like the ideal solution to me, also, until I actually tried it.
However, the Enter event fires BEFORE the Click event. Thus, when the user
clicks in the field, the Enter event selects the entire contents based on my
code, and the subsequent Click event performs its default action, which is to
place the cursor at the clicked location. This effectively overrides the
effect of the Enter event.

I may just have to use the DblClick event, since it is an event that can be
cancelled, and I can use it to select the entire field rather than its
default behavior of selecting the portion of the time/date between the
punctuation marks (colon or slash).
 
S

Steve Schapel

Brian,

I'm pretty sure you won't have to explicitly code this for the Dbl Click
event, I think you'll find this is the default behaviour for Dbl Click
anyway.
 
G

Guest

Actually, when using date/time formats for the text box, the DblClick
defaults to selecting just the portion of the date/time between the
punctuation marks. That is, when I double-click on a Short Time text box that
already contains 12:31, it will select "12" or "31", depending on where I
double-click. The same is true for dates. Double-clicking in a Short Date
field containing 12/22/04 will select "12", "22", or "04", depending on the
exact mouse position at the double-click.

I understand that DblClick is a cancellable event, however, so it can be
cancelled and code inserted to modify its default. I have not yet tried this,
but that is the next step.
 

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