Solved Set Cursor at Beginning of Text Box

Eljefegeneo

Still trying to learn
Local time
Yesterday, 16:29
Joined
Jan 10, 2011
Messages
902
This has been driving me crazy for the last hour. Should be simple but it just doesn’t want to do what I want it to do. Set the cursor at the beginning of the text box if the box is void of any data. I have tried the following but nothing seems to provide me with the required results. It is a simple text box that has an input mask of 00000. I’ve tried each of the below using the OnFocus and OnMouseDown events to no avail. And to boot, even without the IF statement it doesn't do anything.

Code:
If Len(Zip) & "" = 0 Then
Me.Zip.SelStart = 0
End if

Code:
If (Zip = "" Or IsNull(Zip4)) Then
Me.Zip.SelStart = 0
End If

Code:
If (Zip.Value = "" Or IsNull(Zip.Value)) Then
Me.Zip.SelStart = 0
End If
 
This seems to work for me.
Code:
Private Sub Field1_Click()
Me.Field1.SelStart = 0

End Sub
 
do it on 2 events, you never know when user will Click or Tab to the control.

Private Sub Zip_GotFocus()
Me.Zip.SelLength = 0
End Sub

Private Sub Zip_Click()
Me.Zip.SelLength = 0
End Sub
 
Thank you. I hadn't tried the on click event. Of course it works fine. Just wondering why it wouldn't work on the OnFocus on OnMouseDown.
 
GotFocus did not work properly. Only the Onclick.
 

Users who are viewing this thread

Back
Top Bottom