Highlighting or Selecting TextBox entry

G

Gus Gazepis

In attempting to trap bad data (for the application) being entered into text
boxes from a form, the exit event of the private sub works well to identify
the problem and return focus to the text box. However, I am not able to
take it a step further and actually highlight (or select) the errant text
for correction. The SelText property doesn't seem to work, or I'm not
applying it correctly.

Thanks,
Gus
 
B

Bob Phillips

Gus,

Do you mean something like

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox1.Text <> "Bob" Then
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)
Cancel = True
End If
End Sub
 
G

Gus Gazepis

Bob,
A thousand thanks! The code works perfectly. I really appreciate the help.

Thanks again,
Gus Gazepis
 
B

Bob Phillips

Thanks Gus, glad to be of help.

Bob


Gus Gazepis said:
Bob,
A thousand thanks! The code works perfectly. I really appreciate the help.

Thanks again,
Gus Gazepis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top