Placing Cursor when Using ".InputMask"

M

Marcel Stoop

Hi

For a textbox I have created a InputMask: Me!txtSchulj.InputMask =
"00\/00;0;."

In the textbox it looks like: ../.. (The / will get saved)

So far so good.
The problem I have is the position of the cursor.
If I click in Textbox Me!txtSchulj, the cursor is always after "../.."

I would like, when doing a mouse Click in Field Me!txtSchulj (or when
Me!txtSchulj gets the Focus) , the cursor to be positioned on the first dot
of "../.." , so that the user can start right away filling out this field:
To be clear: The cursor should be positioned at the start of the field.

I have tried already to use ! within different Positions of "00\/00;0;.",
without any results.

Is it possible to move the cursor to the start of the field when this field
has got an InputMask?

Thanks for the help.
 
G

Gary Walter

Hi Marcel,

For just the one textbox, in code
behind its appropriate event
(say, Got_Focus), you might play
with SelStart and SelLength:

Me!txtSchulj.SelStart = 0
Me!txtSchulj.SelLength = 1

For all controls, from top menu

Tools/Options/Keyboard/
--Behavior Entering Field
----Go To Start of Field

good luck Marcel,

gary
 
D

Dirk Goldgar

Marcel Stoop said:
Hi

For a textbox I have created a InputMask: Me!txtSchulj.InputMask =
"00\/00;0;."

In the textbox it looks like: ../.. (The / will get saved)

So far so good.
The problem I have is the position of the cursor.
If I click in Textbox Me!txtSchulj, the cursor is always after "../.."

I would like, when doing a mouse Click in Field Me!txtSchulj (or when
Me!txtSchulj gets the Focus) , the cursor to be positioned on the
first dot of "../.." , so that the user can start right away filling
out this field: To be clear: The cursor should be positioned at the
start of the field.

I have tried already to use ! within different Positions of
"00\/00;0;.", without any results.

Is it possible to move the cursor to the start of the field when this
field has got an InputMask?

Thanks for the help.

This is tricky, because clicking in the text box makes Access want to
position the text caret at the location clicked. There may be some
other way around it, but I remember working on this question once and
the only solution I can remember is to put a transparent command button
or label on top of the text box, with its Tab Stop property set to No,
and a Click event procedure along these lines:

'----- start of example code -----
Private Sub cmdFixFocus_Click()
Me!txtSchulj.SetFocus
Me!txtSchulj.SelLength = 0
Me!txtSchulj.SelStart = 0
End Sub
'----- end of example code -----
 
M

Marcel Stoop

Thanks Dirk

Gary's solution does not really do the trick.
I noticed, when building in a dummy MsgBox on get focus event on
Me!txtSchulj, the cursor jumps to the start.
So I think your approach is pretty promising.

I will try it right away this evening and will keep you updated.

Again, thanks for the help.

Cheers
Marcel
 
G

Gary Walter

For the record.....

I tested a form with a textbox "txtTask"
whose InputMask was 00\/00;0;.

The "option setting" always made
it start at beginning when tabbed to
the textbox.

For selection with mouse,
this code seemed to do the
trick for me (Access XP):

Private Sub txtTask_Click()
Me!txtTask.SelStart = 0
Me!txtTask.SelLength = 1

End Sub

Gary Walter (Ex-Access MVP)
 
M

Marcel Stoop

I do not now why to disregard it......

But I found out myself that putting your code on a Click event will do the
trick. So there is no need, as Dirk proposed, to create a phantom Button,
although also that option will do the trick.

Cheers
Marcel
 

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