Date field

  • Thread starter Thread starter eric gunther
  • Start date Start date
E

eric gunther

I have two date fileds in a currenmt table. The first is
manufacturing date and the second is expiration date. The
expiration is usually 3 years from the date of manufacture
but I find a lot of operators entering current years for
both dates by mistake. How can I put a validation rule in
the expiration column that the date entered in it must be
at least two years after the date in the manufacturing
column. I can't find the right validation rule text to
put in.

Thank you
 
Use the BeforeUpdate event procedure of the *form* to notify the user if the
date looks wrong:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If DateDiff("d", [ManufacturingDate], [ExpirationDate]) < 730 Then
If MsgBox("That soon?", vbYesNo+vbDefaultButton2) <> vbYes Then
Cancel = True
End If
End If
End Sub


If the 3 years is common, you may also want to help them fill it in:

Private Sub ManufacturingDate_AfterUpdate()
If IsNull(Me.[ExpirarionDate]) Then
Me.[ExpirationDate] = DateAdd("yyyy", 3, Me.[ManufacturingDate])
End If
End Sub
 
Back
Top