Input Mask Issue

BrettM

just a pert, "ex" to come
Local time
Tomorrow, 07:36
Joined
Apr 30, 2008
Messages
134
Hi guys,

I have a text box with a simple input mask to force numbers only. My problem is that I want to be able to click in the box and have the cursor always go to the beginning of the mask on initial entry - not directly under the mouse pointer. Is this possible?

Thanks.
 
As you've found out, when using imput masks is that the user may not always arrive at the control by tabbing to it from the previous control, but may click on the control. If a mask is being used and the user doesn't click to insert the cursor at the very beginning of the text box, he/she may start to enter data without realizing that they're not at the beginning. When they leave the control they'll get an error message because the data wasn't entered as the input mask dictated. They'll then have to go back and re-enter the info. The way to avoid this is to use something like this:

Code:
Private Sub YourControlName_Click()
    YourControlName.SelStart = 0
End Sub
Even tabbing to the control can be problematic if in the Options for the database the default behavior for "Entering Field" is set to anything other than "Go to start of field." The answer to this is to set the cursor to the beginning of the field when the field is tabbed into:

Code:
Private Sub YourControlName_GotFocus()
    YourControlName.SelLength = 0
End Sub

Common sense would dictate that the second snippet of code should work for both cases, since click into the field should mean the textbox has focus, but for some reason this doesn't work for all versions.
 
Thanks Linq.

I was trying to use this format earlier but with no success - was attempting to apply it to the On Enter event only.

I note that you are using both SelStart and SelLength. I am now using both to see if there is already data in the textbox and selecting the entire field if there is data present - IsNull, Len() etc. I don't quite follow how the SelLength functions on it's own though as in your GotFocus case.

Regards Brett
 
Sorry, that was a typo! Should have been the same:
Code:
Private Sub YourControlName_GotFocus()
    YourControlName.SelStart = 0
End Sub
 

Users who are viewing this thread

Back
Top Bottom