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!
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 ~
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 ~
'*************** 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 *******************************************************
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.
Help: Application.Screen property
Help: TextBox.SelStart property
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.
here's the link for this page in case you want to copy it:
http://msaccessgurus.com/VBA/Code/Control_GoStart.htm
Email me anytime at info@msAccessGurus
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
~ crystal