Setting cursor leftmost in a date field

G

GaryS

I have a form with a bound short date field on it.

The input mask is 00/00/0000

When the cursor ends up in that control, I want it to be
positioned at the left end rather than the right (so the
user can type the date in in a mmddyyyy order of digits).

Using direct keystrokes, I can get it to go Left in Form
View by hitting Home.

So I figured I could use SendKeys {HOME} in an mHome
macro to do the same.

The problem is figuring out in which Event to use mHome.
If I put in in the On Click event, it works when I use the
mouse to put the cursor in that control but not when I tab
into it.

I have tried On Got Focus and On Enter, but neither seems
to work (using either tabbing or mousing).

I've run out of ideas. Anyone know of a solution?

Gary
 
J

John Vinson

When the cursor ends up in that control, I want it to be
positioned at the left end rather than the right (so the
user can type the date in in a mmddyyyy order of digits).

Of course training the users to *tab* into the field rather than using
the mouse will save them time (and help prevent carpal tunnel syndrome
too)...

SendKeys is flaky and unreliable, and not the best method in any case.
Try the following in the control's GotFocus event:

Private Sub txtDatefield_GotFocus()
Me.SelStart = 1
End Sub
 
G

GaryS

Yes, I have found SendKeys unpredictable, too; glad it's
not just me!

BTW, you use the statement Me.SelStart:

What is the technical definition of "Me"? I see it used
in many different contexts but get no hits on it in MS
Access Help. Sometimes it seems to refer to a Form and
sometimes to a control. Sometimes it is "Me!" and
sometimes "Me."

And where is there a description of available object
methods like SelStart?

Thanks.

Gary

-----Original Message-----
 
J

John Vinson

What is the technical definition of "Me"? I see it used
in many different contexts but get no hits on it in MS
Access Help. Sometimes it seems to refer to a Form and
sometimes to a control. Sometimes it is "Me!" and
sometimes "Me."

IME Me always refers to the Form containing the module with the VBA
code referencing Me. It's never a control (unless there's some syntax
with which I am not familiar). It's just a shortcut for
Forms!NameOfForm.

The ! and . are *almost* interchangable in this context. ! means that
what follows is a member of a collection - e.g. Forms!MyForm!txtXYZ is
synonymous with Me!txtXYZ (if the code is part of MyForm's module);
either way looks at the default collection of the Form - the Controls
collection - for a member named txtXYZ. The period operator refers to
a Method of the object preceding it - and the default Method for a
form object is its control.
And where is there a description of available object
methods like SelStart?

Buried, hard to dig out, in the wretchedly-indexed Access2xxx Help;
scattered through the pages of many Access books; and embedded (in a
more or less readily accessible manner) in the brains of experienced
Access developers. Wish I could point you to a simple reference -
there may be one, but if so I don't know where it is.
 
G

GaryS

John, thanks much for an informative reply!

You write: " . . . IME Me always refers to the Form
containing the module with the VBA code referencing Me.
It's never a control . . . "

OK, but now I don't understand the reference to Me in your
suggested sub:

Private Sub txtDatefield_GotFocus()
Me.SelStart = 1
End Sub

I was thinking that SelStart had to be a Property of the
datefield and the Sub sets it to 1. But if Me represents
the whole Form, then what does "Me.SelStart = 1" do?

You also wrote: " . . . and embedded (in a more or less
readily accessible manner) in the brains of experienced
Access developers."

All I can say is: Newbie.SendThanks LuckyStars

-----Original Message-----
 
J

John Vinson

John, thanks much for an informative reply!
I was thinking that SelStart had to be a Property of the
datefield and the Sub sets it to 1. But if Me represents
the whole Form, then what does "Me.SelStart = 1" do?

Generates an error message, because I simply typed it wrong.

It should be Me!controlname.SelStart = 1
 

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