Results 1 to 4 of 4
  1. #1
    Join Date
    May 2009
    Posts
    41

    Unanswered: How do you turn off field validation in a form?

    I have a form that uses a table as its record source, and there are several fields that have the Required property set to True... which is good...

    but in the form, it's not so good because when a user is tabbing through the fields, Access keeps throwing up an error message along the lines of "You must enter a value in this field."

    What if the user doesn't want to enter a value at that exact moment? Additionally, validation is also set up in the code. I've considered setting the required property to False, since it's set up in the code, but I don't think that's a good way to get around it.

    Any ideas?

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Sorry, but all of this doesn't add up. If a field is declared as Required in the table defs, Access will not throw up an error message when the user tabs thru the field. It will only throw up a warning when the user tries to leave the record, which causes Access to attempt to save the record.

    If tabbing thru the field on the form is causing an error message to pop up, it is being caused by validation code in the form. And if this is happening, it also means that the validation code is in the LostFocus or OnExit event of the textbox, which is not where it should be! Placing it in one of these events for the control is incorrect because

    • It will fire every time you tab thru the control (as you're seeing)
    • The user simply has to not enter the control for the validation code to be rendered useless

    Validation code intended to insure that a given control is not left empty must be in the Form_BeforeUpdate event. This will then only fire when Access tries to save the record, not every time you tab thru the textbox.

    And yes, if you're doing validation at form level, you should set the Required Property in the table defs to No. Trying to validate the data at the table level and the form level means you will get two different warnings if it's left empty. So

    • Change the Required Property, in the table, to No
    • Move the validation code from wherever it currently is to the Form_BeforeUpdate event

    This should fix your problems.

    Note that while validation code to insure that a field is not left empty belongs in the Form_BeforeUpdate event, code to validate that data in a given control conforms to a certain criteria (for example, that it is numeric, or that it is so many characters long, etc) can be placed in the control's BeforeUpdate event because this will only fire if data is entered or edited in this control, not merely because the user tabs thru it.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    May 2009
    Posts
    41
    Quote Originally Posted by Missinglinq
    Sorry, but all of this doesn't add up. If a field is declared as Required in the table defs, Access will not throw up an error message when the user tabs thru the field. It will only throw up a warning when the user tries to leave the record, which causes Access to attempt to save the record.

    If tabbing thru the field on the form is causing an error message to pop up, it is being caused by validation code in the form. And if this is happening, it also means that the validation code is in the LostFocus or OnExit event of the textbox, which is not where it should be! Placing it in one of these events for the control is incorrect because

    • It will fire every time you tab thru the control (as you're seeing)
    • The user simply has to not enter the control for the validation code to be rendered useless

    Validation code intended to insure that a given control is not left empty must be in the Form_BeforeUpdate event. This will then only fire when Access tries to save the record, not every time you tab thru the textbox.

    And yes, if you're doing validation at form level, you should set the Required Property in the table defs to No. Trying to validate the data at the table level and the form level means you will get two different warnings if it's left empty. So

    • Change the Required Property, in the table, to No
    • Move the validation code from wherever it currently is to the Form_BeforeUpdate event

    This should fix your problems.

    Note that while validation code to insure that a field is not left empty belongs in the Form_BeforeUpdate event, code to validate that data in a given control conforms to a certain criteria (for example, that it is numeric, or that it is so many characters long, etc) can be placed in the control's BeforeUpdate event because this will only fire if data is entered or edited in this control, not merely because the user tabs thru it.
    Hi Missinglinq, thanks for the great info.

    You're right about that first part: the user isn't just tabbing through the field... it first has to be edited, then cleared, then tabbed out of (i.e. a user enters a value in a textbox then clears it all, and then tabs to the next field)

    I think it was an issue with not allowing zero-length strings, when I set that to True (just to test it), that message didn't show up.

    But I'm glad to know that I can set the Required property to False if I'm going to be validating in the code.

    Thanks

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Glad we could help!
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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