Set the cursor position

  • Follow


I have a field with an input mask.  When the user wants to type in that 
field, they sometimes simply click in the field and start typing.

But I want them to always start entering data at the first position of the 
field (which is usually not where they click).

What sort of VBA code would I use to move the "cursor" to the first position 
of the field (I assume this would be in a GotFocus event ... or something 
like that)??

thanks.   bob. 


0
Reply Bob 3/11/2008 9:28:34 PM

On Tue, 11 Mar 2008 14:28:34 -0700, Bob Howard wrote:

> I have a field with an input mask.  When the user wants to type in that 
> field, they sometimes simply click in the field and start typing.
> 
> But I want them to always start entering data at the first position of the 
> field (which is usually not where they click).
> 
> What sort of VBA code would I use to move the "cursor" to the first position 
> of the field (I assume this would be in a GotFocus event ... or something 
> like that)??
> 
> thanks.   bob.

If the user clicks into the field, the cursor position will be where
ever the user has clicked.

If the user tab's into the field, you can position the cursor at the
beginning.
Code the control's Enter event:

Me.[ControlName].SelStart = 1

Or ...

to position it at the end of the existing data, you can use:

Me.[ControlName].SelStart = Len(Me.[ControlName])


-- 
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
0
Reply fredg 3/11/2008 9:49:54 PM

"fredg" <fgutkind@example.invalid> wrote in message 
news:1f9ot7jbk0m33$.6n9iyhrn7puc.dlg@40tude.net...
>
> If the user clicks into the field, the cursor position will be where
> ever the user has clicked.


There's a workaround for this, but it may be more trouble than it's worth. 
You can cover the text box with a transparent command button, making sure 
that (a) the command button is in front of the text box, and (b) the command 
button's Tab Stop property is set to No//False.  Then you can the command 
button's Click event procedure to set the focus to the text box.

-- 
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

0
Reply Dirk 3/11/2008 10:05:25 PM

OnEnter only works if the textbox is tabbed into, not if it's clicked in.

Private Sub YourTextBox_Click()
  Me.YourTextBox.SelStart = 0
End Sub

-- 
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200803/1

0
Reply Linq 3/12/2008 3:21:42 AM

3 Replies
2368 Views

(page loaded in 0.043 seconds)


Reply: