Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2005
    Posts
    20

    Red face Unanswered: validating txt box

    Hi,

    I have tried some code a few users have given me and none have worked. All I want to do is the following:

    I have a text box on my access form. Well I want access to be able to be able to tell if the txt box contains text or is blank. If the text box is left blank, I want a message box to appear stating "Please enter text". If the text box has text, I just want to be able to go on to the next text box.

    There has to be a way to do this.

    I tried this code:

    If text46 = "" then
    msgbox "Enter data"
    else
    cancel = true
    end if

    This does not work. All it does is when I enter a value into text46, it will not let me go to the next text box. This is the complete opposite of what I want to happen. I want that to happen when the box is left blank. Please help I am about to give up

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    did your users give you the context they used that fragment of VB as well

    what are you intending to do with cancel. Normally I'd expect to see cancel set in this manner in a form or controls before update event.

  3. #3
    Join Date
    Dec 2005
    Posts
    4
    You should check on the "OnFocus" and "LostFocus" events... or are these the right names for them? I don't remember but it's near to that.

  4. #4
    Join Date
    Nov 2002
    Posts
    272
    Quote Originally Posted by benz84
    If text46 = "" then
    msgbox "Enter data"
    else
    cancel = true
    end if
    'Cancel = True' is in the 'else' branch, so something will be canceled when the textbox is NOT empty. Is that what you intend to do?

  5. #5
    Join Date
    Nov 2005
    Posts
    20
    All I want to do is make someone enter data in the text box before they go on to the next. if the text box is left blank i want it to prompt them to enter info before proceeding.

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    What event(s) is you code being called from?

    ivons already identified a probable source of problems, but its difficult to assist if you don't tell the full story,

  7. #7
    Join Date
    Dec 2004
    Location
    Tennessee
    Posts
    31

    Talking

    Benz,
    I agree, the "cancel=true" statement is what's giving you the bug. Try this:

    Code:
    If text46 = "" then
    msgbox "Enter data"
    else
    endif
    This should do what you're wanting...while the textbox is blank, msgbox opens "enter data" other wise if there is text, end the if statement.

    Hope that helps,

    G~
    The older I get, the more new stuff I tend to forget, the stuff I don't use any more...now that I remember!

    Mail Me

Posting Permissions

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