Testing for Null in Subform

W

WPW07

Hello Everyone,

I have a subform with several check boxes and text fields. If a user
goes to the subform, clicks on some check boxes, then unchecks them,
or clears a text box, a record is getting saved in the table bound to
the subform. Is there a way to prevent the record from getting saved
unless there is data in at least one of the text fields, or at least
one of the check boxes is true?

Alternatively, in a query, is there a way to return results only if at
least one of the check boxes is true or one of the text boxes is nut
null? Other than putting "Is Not Null" in each column of the query?

Thank you
 
P

Pieter Wijnen

In the SubForms Before_Update Event you could put

Private Sub Form_BeforeUpdate(Cancel as Integer)
Dim Skip As Boolean
Dim C As Control

For Each C In Me.Controls
If C.Name <> "TheParentLinkControl" Then ' the parent/child link
If Not IsNull(C.Value) Then
Skip = True
Exit For
End If
End If
Next
Cancel = Not Skip
End Sub

HtH

Pieter
 

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