Field Required based on another fields value

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!
 
D

Douglas J. Steele

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top