Mandatory fields

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with 5 fields on it and these fields are 'Required' before the
form can be saved. A message pops up to advise that all fields need to be
filled in if you try and save the form. One field is a drop down box choice
of 'Pass' or 'Fail' and I would like to add another field called 'Comments',
that the rule above still applies, but if 'Fail' is chosen then the
'Comments' field must also be filled in.

I only require the 'Comments' field to be filled in if 'Fail' is chosen.

Cheers
 
Assuming that Field1 is a Text field that contains the words 'Pass' or
'Fail', this should do it:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If (Me.[Field1] = "Fail") And IsNull(Me.Comments) Then
Cancel = True
MsgBox "Comments required when Field1 is 'Fail'."
End If
End Sub

You will need to adjust the code if Field1 contains a numeric or boolean
value.
 
maybe just make a CommentField with its property Visible=No

and then the combobox Pass/Fail you can make on the AfterUpdate Event;

If Me.PassFailName= "Fail" Then
Me.CommentField.Visible=True
End If
 

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

Back
Top