Solved Set Cursor at Beginning of Text Box (1 Viewer)

Eljefegeneo

Still trying to learn
Local time
Today, 11:34
Joined
Jan 10, 2011
Messages
904
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
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:34
Joined
Oct 29, 2018
Messages
21,474
This seems to work for me.
Code:
Private Sub Field1_Click()
Me.Field1.SelStart = 0

End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:34
Joined
May 7, 2009
Messages
19,245
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
 

Eljefegeneo

Still trying to learn
Local time
Today, 11:34
Joined
Jan 10, 2011
Messages
904
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.
 

Eljefegeneo

Still trying to learn
Local time
Today, 11:34
Joined
Jan 10, 2011
Messages
904
GotFocus did not work properly. Only the Onclick.
 

Users who are viewing this thread

Top Bottom