I want to have the last character of the text selected when I ENTER the text box. Seems like it should be simple. However the behavior is inconsistent.
To demonstrate, simple form with two textboxes and a commandbutton.
Tabbing into textbox1 results in all of the text being selected.
Clicking into textbox1 results in no selection at all.
Clicking commandbutton1 results in the desired situation, tb1 with focus, last character selected.
What am I missing?
To demonstrate, simple form with two textboxes and a commandbutton.
Code:
Private Sub CommandButton1_Click()
With TextBox1
.SelStart = Len(TextBox1.Value) - 1
.SelLength = 1
End With
TextBox1.SetFocus
End Sub
-------------
Private Sub TextBox1_Enter()
With TextBox1
.SelStart = Len(TextBox1.Value) - 1
.SelLength = 1
End With
End Sub
-----------------
Private Sub UserForm_Initialize()
TextBox1.Value = "ABCD"
End Sub
Tabbing into textbox1 results in all of the text being selected.
Clicking into textbox1 results in no selection at all.
Clicking commandbutton1 results in the desired situation, tb1 with focus, last character selected.
What am I missing?