Link to home
Start Free TrialLog in
Avatar of SteveL13
SteveL13Flag for United States of America

asked on

Filter a subform based on a checkbox

I have a form that has a sub-form.  The subform is a datasheet.  On the main form is a checkbox named chkPrint.  when the user clicks the checkbox I want only the records in the subform to show those with a Code that equals "P".  

Here is what I have but it doesn't work.

    Me.subfrmVendorList.Form.Filter = "Code =" & chkbxPrint.Value
    Me.subfrmVendorList.Form.FilterOn = True
Avatar of Daniel Pineault
Daniel Pineault

How about something along the lines of
Private Sub chkPrint_Click()
    On Error GoTo Error_Handler

    If Me.chkPrint = True Then
        Me.subfrmVendorList.Form.Filter = "Code='P'"
        Me.subfrmVendorList.Form.FilterOn = True
    Else
        Me.subfrmVendorList.Form.FilterOn = False
    End If

Error_Handler_Exit:
    On Error Resume Next
    Exit Sub

Error_Handler:
    MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: chkPrint_Click" & vbCrLf & _
           "Error Description: " & Err.Description & _
           Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
           , vbOKOnly + vbCritical, "An Error has Occured!"
    Resume Error_Handler_Exit
End Sub

Open in new window

Daniel's solution should work.....
ASKER CERTIFIED SOLUTION
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Curious if you tried the code I proposed earlier, if you experienced any issues?
Avatar of SteveL13

ASKER

It does work.  Just a lot more code.  Right?