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

  • Thread starter Thread starter Lythandra
  • Start date Start date
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
 
Private Sub MyTextbox_GotFocus()

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

End Sub
 
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
 
Back
Top