EASY question regarding validating a text box
Hello
I have a text box, lets call it txtBob. When the user enters something in txtBob and leaves the field I have some validation that checks the data is good.
What I want... is when the data is not good, a message comes up saying "Bad data BAD", I've got this far. Then I also want the cursor to stay in that box (i.e. not tab to the next text box).
I tried putting it on the exit sub for txtBob, but then unfortunately it becomes stuck in that box (i.e. the user cant click the cancel because it keeps checking the text box).
Is there a way, I can have the message and cursor stay in txtBob, while still allowing the user to click into another field/button.
Thanks heaps for you help
Ange
P.S. :afrog: <- what a strange Smiley
Re: EASY question regarding validating a text box
Put the validation code in the textbox's Validate event and if the validation fails set Cancel = True.
Re: EASY question regarding validating a text box
Thanks MartinLiss!
Unfortunately we dont appear to have a validate event on our text box. It could be because we are using VB version 97?
Any other ideas?
Thanks again
Ange
Re: EASY question regarding validating a text box
Re: EASY question regarding validating a text box
Re: EASY question regarding validating a text box
Try the TextBox1_Exit Sub:
VB Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
End Sub
Re: EASY question regarding validating a text box
Quote:
Originally Posted by Psycho_NZ
Yes! Sorry.. VBA 97
OK, I moved the thread.
Re: EASY question regarding validating a text box
Hi
Sub TextBox1_Exit() does the trick, the chap I was helping out got me confused. We had it all along, duh.
Thanks all :)
Ange
:afrog: :afrog: :afrog:
Weird frogs...