I have the following Main Form "Edit Services" with a Sub Form "Edit Services SubForm":
I want to filter the Sub Form based on the check box at the top of the Main Form that correlates to fields in the Sub Form that are on a Yes/No criteria.
I.E. If the In-Shop box is checked then it should filter anything that has In-Shop as Yes in the Sub Form. If it is unchecked it should clear the filter.
ANSWER
Private Sub chbxInShop_Click()
If Me.chbxInShop.Value Then
Me.[Edit Services SubForm].Form.Filter = "[SrvInShop] = True"
Me.[Edit Services SubForm].Form.FilterOn = True
Me.[Edit Services SubForm].Form.Requery
End If
End Sub
Based on your sample database, it seems the code had the True and False conditions reversed. For example, the following line means "If chbxInShop is False (un-checked) then do the following", which is to apply the subform filter. But you really want to apply the filter when the check box is checked ... meaning its .Value
is True (-1).
If Me.chbxInShop.Value = 0 Then
I tested the following code for the check box's After Update event with your form, and it does what I think you're asking for.
Private Sub chbxInShop_AfterUpdate()
Dim strFilter As String
strFilter = vbNullString ' make it explicit
If Me.chbxInShop.Value = True Then
strFilter = "[SrvInShop] = True"
End If
With Me.[Edit Services SubForm].Form
.Filter = strFilter
.FilterOn = Me.chbxInShop.Value
End With
End Sub
If you later decide you want the subform filter based on the values of all 4 of the form's check boxes, you'll need to examine each of them and create an appropriate Filter
string, which could wind up as something like ...
strFilter = "[SrvInShop] = True AND [SrvSmallBusiness] = True"