Textboxes on userforms

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
 
J

joel

Private Sub TextBox3_Change()
If IsNumeric(Me.TextBox1) Then
Me.TextBox3.SetFocus
end if
End Sub
 
L

Libby

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
 

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