Solved

Validation Rule for table field

Posted on 2008-10-07
4
380 Views
Last Modified: 2013-11-29
I have created an Access table for contracts that has two fields identifying the (contract) start date and the (contract) end date.  I thought I could have a validation in the table design for the "end date" that says < "start date", but it doesn't seem to want to let me do this.  The error (though cryptic to me) say:

"Invalid SQL Syntax - Can't use multiple columns in a column-level CHECK constraint".

What have I done wrong, and how can I make that validation?  Thanks.  - Tom
0
Comment
Question by:tomfarrar
  • 2
  • 2
4 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 22661010
You cannot compare column values that way in a table-level validation rule.

What you should do instead is use a form for data entry/edit, and use the form's BeforeUpdate event
to perform the validation:

Private Sub Form_BeforeUpdate(Cancel As Integer)

    If [EndDate] < [StartDate] Then
        Cancel = True
        MsgBox "Invalid end date", vbCritical, "No soup for you!"
    End If

End Sub
0
 
LVL 7

Author Comment

by:tomfarrar
ID: 22661081
Thanks, Patrick.  Not having done that before, is that as simple as going to the Form's properties, selecting BeforeUpdate>Event and pasting the code into the window?  - Tom
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 250 total points
ID: 22661160
Almost :)

On the events tab, click on the before update event for the form, click the "..." and go to the code builder.
That will create the shell of the sub for you; you just need to put in the filling.
0
 
LVL 7

Author Closing Comment

by:tomfarrar
ID: 31503908
That should get 'er done.  Thanks, Patrick....
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

760 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

26 Experts available now in Live!

Get 1:1 Help Now