Results 1 to 3 of 3

Thread: EASY question regarding validating a text box

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    New Zealand
    Posts
    268

    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

  2. #2
    Addicted Member malik641's Avatar
    Join Date
    Sep 2005
    Location
    South Florida :-)
    Posts
    221

    Re: EASY question regarding validating a text box

    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




    If you find any of my posts of good help, please rate it

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: EASY question regarding validating a text box

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width