Field Required based on another fields value

  • Thread starter Thread starter mazer77
  • Start date Start date
M

mazer77

In a form, how do you require a value in a field based on the value of the
first field. For instance, if field one's value is "fail" then a date is
required in field two. If field one is "passed" then a date is not required
in field two.

Thanks in advance!
 
Put code in the form's BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Field1 = "Fail" Then
If IsNull(Me.Field2) = True Then
MsgBox "You must provide a date in Field2."
Cancel = True
Else
If IsDate(Me.Field2) = False Then
Msgbox "Field2 doesn't contain a valid date."
Cancel = True
End If
End If
End If

End Sub
 
Back
Top