Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Validation Rule for table field

Posted on 2008-10-07
4
Medium Priority
?
389 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 93

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 93

Accepted Solution

by:
Patrick Matthews earned 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…

618 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