Date Validation

matthewnsarah07

Registered User.
Local time
Today, 05:24
Joined
Feb 19, 2008
Messages
192
I have got a table tblLeaveRequest which has 3 date fields in; [DateofRequest], [DateFrom] & [DateTo] which are used on frmLeaveRequest

I want to add some validation rules to these fields:

[DateofRequest] - needs to restricted to dates no older than 10 days prior to system current date and no dates in the future at all

[DateFrom] - if possible to able to enter a date that is more than 12 months into the future

[DateTo] - cannot be before DateFrom field

I have been reliably informed that this too complex at table level

Thanks for your help as always
 
Apologies

It should read:

[DateFrom] user not able to enter a date that is more than 12 months in to the future based on system date

Thanks
 
This validation code will fulfill your needs as posted:

Code:
Private Sub DateOfRequest_BeforeUpdate(Cancel As Integer)
 If (DateDiff("d", DateOfRequest, Date) > 10) Or DateOfRequest > Date Then
   MsgBox "Request Date Must Be No Greater Than 10 Days Prior To Today and No Greater Than Today"
   Cancel = True
 End If
End Sub
Code:
Private Sub DateFrom_BeforeUpdate(Cancel As Integer)
If DateDiff("d", Date, DateFrom) > 365 Then
  MsgBox "'Date From' Cannot Be Greater Than One Year In The Future"
  Cancel = True
End If
End Sub
Code:
Private Sub DateTo_BeforeUpdate(Cancel As Integer)
 If DateTo < DateFrom Then
   MsgBox "'Date To' Cannot Be Prior to 'Date From'"
   Cancel = True
 End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom