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

瘦欲@ 提交于 2019-12-02 13:44:18

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!