Clicking in Text Box - How To Auto Put Cursor To Left Side?

L

Lythandra

Sometimes the users can really be annoying with inane stuff but they sign my
checks.

My question is this:

When clicking into a text box, how do I get the cursor to automatically go
to the left side of the box? Kinda like an auto Home keypress ...

thanks
 
D

Douglas J. Steele

Private Sub MyTextbox_GotFocus()

Me.MyTextbox.SelStart = 0
Me.MyTextbox.SelLength = 0

End Sub
 
G

gllincoln

Hi Lythandra,

As long as they are paying for your time and you aren't being asked to clean the windows... does it matter? <grin>

Take a look at the SelStart and SelLength properties - I didn't verify this, but I think these are runtime properties only (not in the property sheet).

Me!txtControlName.SelStart=0 'char pos of cursor from 0 to length of content string
Me!txtControlName.SelLength=0 'how many char selected

Seems like the onClick event would be an appropriate place to do the deed, but onEnter would probably serve the purpose also.

These are interesting and useful properties to manipulate the behavior of the textbox and the cursor.

You can 'select all' - place the cursor at the end of contents or the start. You can search the contents of a text box for a substring, then use these properties to set the cursor at the searched for word or phrase and select the word or phrase (if you want to). Sooner or later you run into a situation where you want/need to do this.

Hope this helps...
Gordon
 

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