Required Field at subform level

G

Guest

I have a check box field in my Main form called "PO_flag." On my subform, I
have a field called "PO_no". If the PO_flag field is "checked" (="Y"), the
PO_no field on the subform must be required (filled in). If not, the message
will be MsgBox "You must enter a PO#." I put the following code in the
Before Update Event procedure but nothing happens. Do I also need code in
the subform under the PO_no field?

Private Sub Check161_BeforeUpdate(Cancel As Integer)

If Me!PO_flag = "Y" Then
MsgBox "You are required to enter a Purchase Order # in the line-item
detail section."
Me!PO_flag.SetFocus
Cancel = True
End If

End Sub

Thank you!
 
A

Allen Browne

Use the BeforeUpdate event of the *form*, not the check box. The event for
the check box will not fire unless the user does something with it.

So you will need something like this in the BeforeUpdate event of the
subform:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Parent!PO_flag.Value Then
If IsNull(Me.PO_no) Then
Cancel = True
MsgBox "PO_no required..."
End If
End If
End Sub

Note that a checkbox has the value True or False, which is not the same as
the text "Y".
 

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