Selecting the entire field after setting focus to it

  • Thread starter Thread starter BPeters
  • Start date Start date
B

BPeters

When setting focus to a field on a form, I'd like the cursor to select the
entire field so it is ready to replace existing data instead of the user
having to double click the field before replacing the data. Thanks.
 
try this:

txtField.SetFocus
txtField.selStart = 0
txtField.selLength = Len(txtField)
 
A good place to do that, Jim is in the GotFocus event of the text box.

Private Sub txtField_GotFocus()
With Me
.txtField.selStart = 0
.txtField.selLength = Len(txtField)
End With
End Sub

(qualify your object references)
 
Thanks to both of you. I'll give it a try.

Klatuu said:
A good place to do that, Jim is in the GotFocus event of the text box.

Private Sub txtField_GotFocus()
With Me
.txtField.selStart = 0
.txtField.selLength = Len(txtField)
End With
End Sub

(qualify your object references)
 
Back
Top