go to the beginning of the input mask Ms Access Gurus

VBA > Control > GoStart of InputMask

Go to the start position if there is no value. This is especially useful for controls with an Input Mask, so no matter where you click, you're at the beginning when you start typing!

Quick Jump

Benefits

Normally, when there isn't a value in a control, and you click into it, you can just start typing without any regards to where the mouse was clicked. With an input mask, however, characters are already there, so when you click in the middle, that is where the cursor is.

Therefore, if you click in the middle, you'll type in the middle ... unless you fix that with a little VBA code ~

Goto Top  

Screen Shot

By triggering this code on the Click event, even when you click in the middle of a control with an InputMask, the cursor goes to the start! ... right where you want to be ~

go to selection start

Goto Top  

Code

'*************** Code Start *****************************************************
' reference:
'  http://msaccessgurus.com/VBA/Code/Control_GoStart.htm
'-------------------------------------------------------------------------------
' Purpose  : Position cursor at start of an InputMask if there is no value
' Author   : crystal (strive4peace)
' License  : below code
' Code List: www.msaccessgurus.com/code.htm
'-------------------------------------------------------------------------------
'           GoStartIfNull
'-------------------------------------------------------------------------------
Private Function GoStartIfNull() 
'200506 strive4peace
' position cursor at start of an InputMask if there is no value
'	avoid problems clicking in middle
' declared as a function instead of a sub
'	to assign on Property Sheet if desired
' works well on Click event of a control
   With Screen.ActiveControl 
      If IsNull(.Value) Then 
         .SelStart = 0 
      End If 
   End With 
End Function 

'   You may freely use and share this code
'     provided this license notice and comment lines are not changed;
'     code may be modified provided you clearly note your changes.
'   You may not sell this code alone, or as part of a collection,
'     without my handwritten permission.
'   Use at your own risk.
'   ~ crystal (strive4peace)  www.msaccessgurus.com
'*************** Code End *******************************************************

Goto Top  

Logic

With the active control on the screen, if there is no value, then go to and select the start.

This code works well when called on the control's Click event.

Goto Top  

Reference

Application.Screen

Docs / Office VBA Reference / Access / Object model / Application object / Properties / Screen

Help: Application.Screen property

ActiveControl

Docs / Office VBA Reference / Access / Object model / Screen object / Properties / ActiveControl

Help: ActiveControl

SelStart

Docs / Office VBA Reference / Access / Object model / TextBox object / Properties / SelStart

Help: TextBox.SelStart property

SelLength

Docs / Office VBA Reference / Access / Object model / TextBox object / Properties / SelLength

Help: TextBox.SelLength property

Goto Top  

Backstory

The biggest inconvenience of using an input mask is that you're dumped exactly where you clicked, which is usually somewhere in the middle, not the beginning. When a control doesn't have a value, it's easy to position the cursor where data entry needs to happen. I wrote a companion procedure to this one, that positions SelStart at the first placeholder to fill. I can post that one too, if anyone asks.

Goto Top  

Share with others

here's the link for this page in case you want to copy it:
http://msaccessgurus.com/VBA/Code/Control_GoStart.htm

Share your comments

Email me anytime at info@msAccessGurus.com. I love hearing about what you're doing with Access.

Are you looking for help with your application?

Let's connect and do it together. As needed, I'll pull in code and features from my vast libraries, cutting out lots of development time.

I'd love to help you! For training or programming, email me at training@msAccessGurus.com

~ crystal

Goto Top