Force cursor to start of text box?

Tim L

Registered User.
Local time
Today, 03:39
Joined
Sep 6, 2002
Messages
414
Is it possible to force the cursor to move to the start of a text box when it gets the focus? (I suppose what I am really asking here is, is it possible to force a 'Home' key event?)

There is a text entry box, which when people put the cursor into it, it sometimes sits part the way in, consequently the operator could end up trying to type in more information than there is available space. I know that education might go along way here, but you just can't teach some people.

Tim
 
The above thread suggests using, in the GotFocus event, the following code
Code:
SendKeys "{F2}", True
Unfortunately this only works on my system if the focus is gained by pressing the Tab key, the cursor still sits neatly in the middle of the text box when the mouse is used to go to it.

If I put in a msgbox instructing operators what to do the cursor moves fine, so thought that there must be a timing problem. I put in a delay routine (not necessarily the best idea given that I can't be sure of the speed of the machines on which the program will be used) but this still resulted in the cursor being in the middle of the text box.

I've now tried chaning the Input Mask for the text box, this works by getting rid of the problem entirely (no need to run the Send Keys code) when I remove it, but is not ideal (for hopefully obvious reasons).

Any other ideas?

Tim
 
Code:
Me.TextBoxName.SetFocus
Me.TextBoxName.SelStart = 0

Regards,
Tim
 
Move cursor to start of text box - success

Thanks for the pointer Tim,

SelStart = 0

did not work in the GotFocus event, so then I tried OnClick, which did work.

I then tried

SendKeys "{F2}", True

in the GotFocus event and that worked too, so it was the choice of event rather than the choice of command.

Note, because the commands work differently the choice of which one to use can be based on whether you want the text selected (use SendKeys) or not (use SelStart).

Tim
 

Users who are viewing this thread

Back
Top Bottom