Multi-Criteria Filter

Nizar

Registered User.
Local time
Today, 08:43
Joined
Oct 21, 2007
Messages
41
Good morning everyone,

I use this code to filter a subform with multiple criteria.

Code:
Private Sub Filter_Click()
Dim strWhere As String
If Not IsNull(Me.Coordinator) Then
        'Create Predicate
    strWhere = strWhere & " AND " & "Orders.[EmployeeID] = " & Me.Coordinator & ""
    End If
        If Not IsNull(Me.Customer) Then
        'Create Predicate
    strWhere = strWhere & " AND " & "Orders.[CustomerID] = " & Me.Customer & ""
    End If
    
    If Not IsNull(Me.Supplier) Then
        'Create Predicate
    strWhere = strWhere & " AND " & "Orders.[SupplierID] = " & Me.Supplier & ""
    End If
    Me.Track_All_Orders.Form.Filter = strWhere
    Me.Track_All_Orders.Form.FilterOn = True
End Sub

This Code works great, however i want to use it to filter my report as well, so I put strWhere as a global var and i wrote this code to generate the report with the same filters criteria as the subform:

Code:
Private Sub cmdGenerateReport_Click()
Dim stDocName As String
stDocName = "Statement"
DoCmd.OpenReport stDocName, acPreview, , strWhere
End Sub

Nothing happen when i click on cmdGenerateReport!! any clue?

Million thanks in Advance,
Best Regards,
 
First, you need to define "strWhere" in the code for cmdGenerateReport.

Try something like this: strWhere = Me.RecordSource
 
Thank you johndoomed for your interest, it works now:)

have a good day,

Best regards
 

Users who are viewing this thread

Back
Top Bottom