Validation Rule in Table

E

Emma Aumack

I am trying to add a validation rule in the "Completed" field of a table as
follows:
=[date_entered]

and I'm getting the error:

Invalid SQL syntax - cannot use multiple columns in a column-level check
constraint.

If I can't do this how can I make sure that the user does not enter a
completed date before the entered date?

Thanks!!
 
E

Emma Aumack

Okay, so I found some code that Ofer provided in a previous post as follows:

Private Sub Competed_BeforeUpdate(Cancel As Integer)

If Not IsNull(Me.Date_Entered) And Not IsNull(Me.Completed) Then
If Me.Date_Entered > Me.Completed Then
msgbox "Date Completed must be after Request Date"
Cancel = True 'wont let the user exit the form
End If
End If

End Sub


My problem now is that when the user goes to enter the date completed, and
it is the same date as date entered (which has a default value of Now()), I
believe access is seeing it as a lesser value.

So what I need to do is somehow get the date entered to be saved as the
straight date (no minutes or seconds included in the value), so that my
comparison will work.

Any ideas on how I can do this?


--
www.bardpv.com
Tempe, Arizona


Emma Aumack said:
I am trying to add a validation rule in the "Completed" field of a table as
follows:
=[date_entered]

and I'm getting the error:

Invalid SQL syntax - cannot use multiple columns in a column-level check
constraint.

If I can't do this how can I make sure that the user does not enter a
completed date before the entered date?

Thanks!!
 
M

Marshall Barton

Emma said:
Okay, so I found some code that Ofer provided in a previous post as follows:

Private Sub Competed_BeforeUpdate(Cancel As Integer)

If Not IsNull(Me.Date_Entered) And Not IsNull(Me.Completed) Then
If Me.Date_Entered > Me.Completed Then
msgbox "Date Completed must be after Request Date"
Cancel = True 'wont let the user exit the form
End If
End If

End Sub


My problem now is that when the user goes to enter the date completed, and
it is the same date as date entered (which has a default value of Now()), I
believe access is seeing it as a lesser value.

So what I need to do is somehow get the date entered to be saved as the
straight date (no minutes or seconds included in the value), so that my
comparison will work.


Change the defult value from Now() to Date() and use an
UPDATE query to remove the time part from existing records:

UPDATE thetable SET Date_Entered = DateValue(Date_Entered)

OR, probably better, change the BeforeUpdate code to:

If DateValue(Me.Date_Entered) > Me.Completed Then
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top