Solved

Validation Rule for table field

Posted on 2008-10-07
4
384 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 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

696 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