Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2004
    Posts
    48

    Unanswered: Access Database - Required fields

    I have 2 databases where I've set up certain fields to be required or not null.
    The fields are required, at the table level, based on a Validation Rule and Validation Text not by setting the property Required to Yes. In one database, this is working perfectly. If a user doesn't fill out one of the "required" fields and tries to close the form using a "close form " command button, the user keeps getting the Validation Text message until they enter data in the field.

    In the other database, the "this field is required message" only pops up if the user closes the form using the built-in X in the corner of the form. If the "close form" command button is used, the form just closes without popping up the validation text. It just seems to be ignoring the validation rules and validation text messages that have been set up.

    The database where this is working correctly was created a few years ago in Access 2000 and later converted to Access 2003. The database where the validation isn't working was created in Access 2003. That's the only difference between the 2 that I can think of.

    Any suggestions?

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    The Validation properties only function during the edit of the field to which the validation properties belong.

    Either use the required property or examine the fields in your BeforeUpdate event procedure.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    As Trekker pointed out, Validation Rules validate that data entered is correct, according to the rules you've set. They don't check to see if any data actually was entered!

    As to the messagebox popping up if the user closes with the X but not if they use a custom Close button genarated by the Wizard, this is a recognized bug that's been present for years, and only fixed with v2007.

    The code generated by the Wizard uses

    DoCmd.Close

    which, as you've found, closes the form without any Warning that validation has been violated. What you haven't noticed yet, apparently, is that it not only doesn't throw up the warning, it also dumps the unvalidated record, rather than saving it to the table!

    The fix for this is quite simple. Find the code for the Close button, and add this line before it, to force a save, which then trips the validation warning:

    If Me.Dirty Then Me.Dirty = False

    so that you end up with

    If Me.Dirty Then Me.Dirty = False
    DoCmd.Close
    Last edited by Missinglinq; 08-06-09 at 21:50.
    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
  •