如何在有条件的情况下输出访问报告 [英] How To Output access Report with Condition

查看:63
本文介绍了如何在有条件的情况下输出访问报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的一天

我有一个表格可以在运行表格时有条件地运行报表

I Have a Form To Run Report With Condition When I Run The Form The Filter(Condition) Work Correctly For Report

但是当我创建PDF(DoCmd.OutputTo)时,PDF返回所有值(过滤器或条件不起作用)。

But When I Create PDF( DoCmd.OutputTo) The PDF Return All Value (The Filter Or Condition Don't Work).

这是我的代码

 fSetAccessWindow (2)
DoCmd.OpenReport "Report1", acViewReport, _
                 "SELECT * FROM main WHERE ID LIKE '" & Nz(Me.cmrtxt, "*") & "' AND place_of_discharge_ar LIKE '" & Nz(Me.dischargecombo, "*") & "' AND border LIKE '" & Nz(Me.bordercombo, "*") & "'  AND a_date Between " & _
                 Format(Nz(Me.statrdatetxt, "01/01/1900"), "\#mm\/dd\/yyyy\#") & " And " & _
                 Format(Nz(Me.enddatetxt, "01/01/2900"), "\#mm\/dd\/yyyy\#"), , acDialog
                Me.Visible = True

                DoCmd.OutputTo acOutputReport, "Report1", "", "", False, "", 0

                 fSetAccessWindow (SW_HIDE)

有人可以为我修复

亲切的问候

推荐答案

我将基于查询创建报表(如果还不是这样的话),并且由于您知道SQL,因此在运行时需要该报表,您可以完全替换QueryDef中的SQL(使用适当的WHERE过滤器),而仅输出报告。您无需事先打开。省略OpenReport调用,然后执行以下操作:

I would base the report on a query (if it's not so already) and since you know the SQL you need for the report at runtime, you can replace the SQL in the QueryDef entirely (with the proper WHERE filter) and just output the report. You do not need to open in beforehand. Omit the OpenReport call and just do something like this:

CurrentDB.QueryDefs("qryMyReportBase").SQL = "SELECT * FROM main WHERE ID LIKE '" & Nz(Me.cmrtxt, "*") & "' AND place_of_discharge_ar LIKE '" & Nz(Me.dischargecombo, "*") & "' AND border LIKE '" & Nz(Me.bordercombo, "*") & "'  AND a_date Between " & _
                                             Format(Nz(Me.statrdatetxt, "01/01/1900"), "\#mm\/dd\/yyyy\#") & " And " & _
                                             Format(Nz(Me.enddatetxt, "01/01/2900"), "\#mm\/dd\/yyyy\#")

DoCmd.OutputTo acOutputReport, "Report1", acFormatPDF, "C:\MySavePath\Report1.pdf", False

很显然, qryMyReportBase应该是报表的源查询, C:\MySavePath\应该是您的保存路径。

Obviously, "qryMyReportBase" should be the report's source query and "C:\MySavePath\" should be your save path.

此外,在OutputTo中,您没有将类型指定为PDF的任何地方。既然是您上面提到的,我就添加了它。

Also, I didn't see anywhere in OutputTo where you were specifying the type as PDF. Since that's what you mentioned above, I've added that in.

这篇关于如何在有条件的情况下输出访问报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆