[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 390
  • Last Modified:

Validation Rule for table field

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
tomfarrar
Asked:
tomfarrar
  • 2
  • 2
1 Solution
 
Patrick MatthewsCommented:
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
 
tomfarrarAuthor Commented:
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
 
Patrick MatthewsCommented:
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
 
tomfarrarAuthor Commented:
That should get 'er done.  Thanks, Patrick....
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now