I made the following code to validate dates entered in a text box.
The code works fine in Access XP but doesn't work in Access 97, 2000.
I have put in down to my bad coding techniques!
Here is the code I have used. Can somebody knock me into shape?
Private Sub txtDispDate_AfterUpdate()
' Check that the date entered is not more than 2 weeks old
If CDate(Me.txtDispDate.Value) + 14 < Me.txtDateTimeKeyed.Value Then
MsgBox "This application is over 2 weeks old. Please ensure that you have entered the correct date. ", vbCritical, "Validation"
Me.txtAppDate.SetFocus
Me.txtDispDate.SetFocus
Exit Sub
End If
' Check that the date entered is not greater that todays date
If Me.txtDispDate.Value >= Me.txtDateTimeKeyed.Value Then
MsgBox "The dispatch date your entered is greater than todays date. Please confirm your entry before you continue.", vbQuestion, "Validation"
Me.txtAppDate.SetFocus
Me.txtDispDate.SetFocus
Exit Sub
End If
' Check that the date entered is not less than txtAppDate value
If Me.DispDate.Value < Me.txtAppDate.Value Then
MsgBox "The dispatch date cannot be before the application date.", vbCritical, "Validation"
Me.txtAppDate.SetFocus
Me.txtDispDate.SetFocus
Exit Sub
End If
Me.chkLockDispDate.Value = True
Me.txtCustName.SetFocus
End Sub
The code works fine in Access XP but doesn't work in Access 97, 2000.
I have put in down to my bad coding techniques!
Here is the code I have used. Can somebody knock me into shape?
Private Sub txtDispDate_AfterUpdate()
' Check that the date entered is not more than 2 weeks old
If CDate(Me.txtDispDate.Value) + 14 < Me.txtDateTimeKeyed.Value Then
MsgBox "This application is over 2 weeks old. Please ensure that you have entered the correct date. ", vbCritical, "Validation"
Me.txtAppDate.SetFocus
Me.txtDispDate.SetFocus
Exit Sub
End If
' Check that the date entered is not greater that todays date
If Me.txtDispDate.Value >= Me.txtDateTimeKeyed.Value Then
MsgBox "The dispatch date your entered is greater than todays date. Please confirm your entry before you continue.", vbQuestion, "Validation"
Me.txtAppDate.SetFocus
Me.txtDispDate.SetFocus
Exit Sub
End If
' Check that the date entered is not less than txtAppDate value
If Me.DispDate.Value < Me.txtAppDate.Value Then
MsgBox "The dispatch date cannot be before the application date.", vbCritical, "Validation"
Me.txtAppDate.SetFocus
Me.txtDispDate.SetFocus
Exit Sub
End If
Me.chkLockDispDate.Value = True
Me.txtCustName.SetFocus
End Sub