PDA

Click to See Complete Forum and Search --> : EASY question regarding validating a text box


Psycho_NZ
Oct 3rd, 2005, 05:17 PM
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

malik641
Oct 4th, 2005, 10:51 AM
Ange,

I don't believe you can have the cursor stay in the text box while the user clicks other buttons, because the focus becomes set on whatever the user clicks last.

If you want the text box that has the wrong information to be selected after the message comes up, just place

txtBob.SetFocus

in the code before the sub ends.

If this didn't help then do you think you could post your code??

HTH

Hack
Oct 4th, 2005, 10:58 AM
If the textbox loses focus (which it will if the user clicks in another field), your will lose the cursor in the textbox.

A possible solution is to use a bad flag boolean. If your validation discovers improper something, somewhere, you can set your bad flag boolean to True. You can still allow the user to move through all of the fields and the what not, but if the bad flag boolean is True, then your Save button will be disabled.

The save button will only be enabled again if the bad flag boolean is set to False, and the only way to reset it to false is fix the bad data.