Access 2007 VBA - Report filter doesn't work until report is reloaded

后端 未结 1 1122
北荒
北荒 2021-01-28 23:33

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

相关标签:
1条回答
  • 2021-01-29 00:01

    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.

    0 讨论(0)
提交回复
热议问题