kylesalone said:
I have two date fields.. One is <dateapptset> and the other is
<dateofappt>.. how can I make sure that <dateapptset> is always an
earlier date than <dateofappt>?
You can enforce this at the table level with a table validation rule,
like this:
[dateapptset]<[dateofappt] Or [dateapptset] Is Null Or [dateofappt]
Is Null
You'd also want to specify an appropriate message in the
ValidationRuleText property.
HOWEVER, the table-level validation should serve only as a backup to the
validation you do in your form, because (a) user entry should only be
made via a form, and (b) you have more control when validating with a
form. So the form where this appointment information is entered should
have a BeforeUpdate event procedure, and that procedure should check
that all the required fields have been entered, and that they are valid
with respect to each other.
Assuming you require both fields to be entered (or defaulted), such an
event procedure might look like this:
'----- start of example code -----
Private Sub Form_BeforeUpdate(Cancel As Integer)
With Me!dateapptset
If IsNull(.Value) Then
MsgBox "Required field not entered.", _
vbExclamation, "Unable to Save"
.SetFocus
Cancel = True
Exit Sub
End If
End With
With Me!dateofappt
If IsNull(.Value) Then
MsgBox "Required field not entered.", _
vbExclamation, "Unable to Save"
.SetFocus
Cancel = True
Exit Sub
End If
End With
If Me!dateapptset >= Me!dateofappt Then
MsgBox "Appointment date must be in the future.", _
vbExclamation, "Unable to Save"
Me!dateofappt.SetFocus
Cancel = True
End If
End Sub
'----- end of example code -----
The above code could certainly be improved, but it should give you an
idea.