Textboxes on userforms

  • Thread starter Thread starter Robert Crandal
  • Start date Start date
R

Robert Crandal

I have a couple textboxes on my userform, but I am mostly
interested in Textbox3. Once a user enters string data
into Textbox3 and presses the Enter key I would immediately
like to check the string. If the string is NOT valid, I would
like the clear out the invalid string from Textbox3. This will
tell the user that the typed data was invalid and that they
need to re-type the data again. If the data IS valid, I would
like the focus to leave Textbox3 (and possibly go to Textbox1)

Does this involve using "TextBox3_AfterUpdate",
"TextBox3_Exit", and the Setfocus() function??? I'm not
sure how to set this up. Please help.

thank you
 
Hi Robert,

Pressing Enter will effectively tab away from teh text box so you could use
the Exit event. You could perhaps negate the need to trap a valid value by
setting the tab order so that TextBox1 is next in line and will get the focus
when enter is pressed with a valid string in TextBox3.

Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
with TextBox3
If .text = 'whatever isn't valid then
.text = ""
.setfocus
end if
end with
End Sub

Libby x
 
Back
Top