Cursor position

A

Abe Katz

Hello,
When I tab from one control to another or use docmd.gotoControl the control
gets highlighted automatically.
Is there a way to put the cursor at the end of the control or at the
beginning of the control without highlighting the control?
Thanks
Abe
 
J

John W. Vinson

Hello,
When I tab from one control to another or use docmd.gotoControl the control
gets highlighted automatically.
Is there a way to put the cursor at the end of the control or at the
beginning of the control without highlighting the control?
Thanks
Abe

Take a look at the SelStart and SelLen properties:

Me!controlname.SelStart = Len(Me!controlname)
Me!controlname.SelLen = 0

will put the cursor at the end, with nothing selected.

It might need to be Len(...) + 1, I haven't used it in a while!
 
A

Al Campagna

Abe,
There are two situations...
When you Tab into the field, or when you mouse click
into the field. (ex. LastName)
This code covers both...
**For cursor at the Beginning of the text string...
Private Sub LastName_Click()
LastName.SelStart = 0
LastName.SelLength = 0
End Sub
Private Sub LastName_Enter()
LastName.SelStart = 0
LastName.SelLength = 0
End Sub

**For Cursor at End of the text string...
Private Sub LastName_Click()
LastName.SelStart = Len(LastName)
LastName.SelLength = 0
End Sub
Private Sub LastName_Enter()
LastName.SelStart = Len(LastName)
LastName.SelLength = 0
End Sub
--
hth
Al Campagna
Microsoft Access MVP 2006-2009
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
J

John W. Vinson

When you Tab into the field, or when you mouse click
into the field. (ex. LastName)

Hrm. I just use GotFocus() to cover both these cases. I can see that you might
want to distinguish them though...
 
J

John W. Vinson

John,
Oh you know me... I always rely on "brute force" in my coding.
:-D
Al

A programmer who lived in Racine
Said, "I can overload any machine -
My secret's aversion
To loops and recursion:
Just acres of in-line routine!"
 
A

Al Campagna

Good one!

And, OT... but one of my favorites...

"Even fleas have little fleas upon their backs to bite 'em.
And little fleas have littler fleas... and so on... ad infinitum."

Al
 
J

John W. Vinson

Good one!

And, OT... but one of my favorites...

"Even fleas have little fleas upon their backs to bite 'em.
And little fleas have littler fleas... and so on... ad infinitum."

to which a physicist replied...

Great vortices have lesser ones
that feed on their velocity;
The lesser ones have lesser ones
and so on, to viscosity.
 
A

Al Campagna

Ha... a keeper!
Al

John W. Vinson said:
to which a physicist replied...

Great vortices have lesser ones
that feed on their velocity;
The lesser ones have lesser ones
and so on, to viscosity.
 

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