I\'m using VBA to dynamically load the content of a report, and depending on which report is selected from the control panel form I\'ve built, the report\'s query might be filte
As @David-W-Fenton suggested, use the WhereCondition with OpenReport instead of setting a Filter expression. Your WhereCondition can be the same string you were using for the Filter expression.
Also, if you give OpenReport an empty string as the WhereCondition, the effect is the same as no WhereCondition, so this (untested) code should work whether or not your getGlobal(1)
returns True.
Dim strWhereCondition As String
Dim strReport As String
strReport = "Test"
If (getGlobal(1) = True) Then
strWhereCondition = "VIP = True"
End If
Select Case Action
Case "View"
DoCmd.OpenReport strReport, acViewReport, , strWhereCondition
Case "PDF"
DoCmd.OpenReport strReport, acViewReport, , strWhereCondition
DoCmd.OutputTo acOutputReport, , acFormatPDF
Case "Print"
DoCmd.OpenReport strReport, acViewPreview, , strWhereCondition
End Select
Notice also that DoCmd.OutputTo, without an ObjectName argument, uses the active object ... which will be the "Test" report in this case.