How can I add a complex validation rule to a field in Access 2003 database?

Posted on 2012-08-29
Last Modified: 2012-08-29
I have a table that I need to add some complex validation in order to keep users from saving a record with invalid data.

Specifically, there is a Taxable field.  If Taxable = No, then there are 4 fields that MUST have something in them before the record can be saved.

So, if Taxable = Yes, record can be saved.

If Taxable = No, record can only be saved if Type <> "" and ExemptNo <>"" and ExpirationDate <>"" and Certificate <> ""

Would I build an expression and put it in the Taxable field?  Or have different expressions in each of the 4 required fields when Taxable = No?

Thanks for any guidance!
Question by:lthames
    LVL 119

    Accepted Solution

    use the beforeUpdate event of the form

    private sub Form_beforeUpdate(cancel as integer)
       select case Me.Taxable
                'continue saving
                  if  Type & ""= "" Or ExemptNo & ""="" Or ExpirationDate & ""="" Or Certificate  & ""= ""  then
                       msgbox "The following fields are required" _
                                & vbcrlf & " Type" _
                                 & vbcrlf & " ExemptNo " _
                                & vbcrlf & " ExpirationDate" _
                                & vbcrlf & " Certificate"    
                  end if

       end select
    end sub

    you can also use the validation codes from this link

    Author Closing Comment

    Thank you!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
    Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
    What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now