sql - 为了以不同的查询定义采用不同的参数的方式实施 MS Access Report,需要采取哪些步骤?
问题描述
在我的工作桌面上,我有
-Microsoft Office Professional Plus 2013 Access
我的任务是创建一个带有 Access DB 的 MS Access 应用程序。
我的应用程序中有一个 MS Access 报告
MS Access 报告的记录源与 MS Access 查询定义相关联
,此外,所述 MS Access 查询定义采用我命名为 idArg 的参数(类型为 Double )。
但是,在 MS Access 报告中,我还有一个 ListBox,它与另一个 MS Access 查询定义相关联,它采用不同的参数,我将其命名为 idArg2 (类型为 Double )。
上述 MS Access 报告最终将用于生成其自身的 pdf 版本。
我从表单的 VB 代码以编程方式生成 pdf:
DoCmd.SetParameter "idArg", CInt(Me.IdLabel.Caption)
DoCmd.SetParameter "idArg2", CInt(Me.IdV2.Caption)
DoCmd.OpenReport "OrgFinancialInstReport", acViewPreview
DoCmd.OutputTo acOutputReport, "OrgFinancialInstReport", acFormatPDF, GetConstructedPdfFileName(CInt(Me.IdLabel.Caption), Me.InvestorName.Caption), True
DoCmd.Close acReport, "OrgFinancialInstReport"
但是,上面显示的代码仅成功地将 CInt(Me.IdLabel.Caption) 正确应用于“idArg”,但未能将 CInt(Me.IdV2.Caption) 应用于“idArg2”
因此,当上面的代码运行时,我看到请求“idArg2”值的弹出框
为了实施所述 MS 访问报告,我必须采取哪些步骤才能正确地将 CInt(Me.IdV2.Caption) 分配给“idArg2”?
解决方案
只需删除查询参数。只需将报告基于原始查询。
然后,过滤报告 - 传递一个“where”子句。
所以:
dim strWhere as string
dim strReport as string
strReport = "OrgFinancialInstReport"
strWhere = "Arg = " & CInt(me.IdLabel.Caption)
DoCmd.OpenReport strReport, acViewPreview,,strWhere
DoCmd.OutputTo acOutputReport, strReport, acFormatPDF,
GetConstructedPdfFileName(CInt(Me.IdLabel.Caption), Me.InvestorName.Caption), True
DoCmd.Close acReport, strReport
对于另一份报告,我们去:
dim strWhere as string
dim strReport as string
strReport = "OrgFinancialInstReport"
strWhere = "Arg2 = " & CInt(Me.IdV2.Caption)
DoCmd.OpenReport strReport, acViewPreview,,strWhere
DoCmd.OutputTo acOutputReport, strReport, acFormatPDF,
GetConstructedPdfFileName(CInt(Me.IdLabel.Caption), Me.InvestorName.Caption), True
DoCmd.Close acReport, strReport
您甚至可以将创建 PDF 的上述代码分解为一个单独的例程 - 从任何形式调用它 - 只需传递报告名称、where 子句,也许还有标题。
那么,当您不提前知道参数的数量时,或者它们会发生变化?只需使用 where 子句。因此,您的查询将没有参数。
推荐阅读
- ruby - 如何从 cron 作业调用的脚本中停止服务?
- python - 如何让我的服务器通过 UDP 多播到 Internet 上的客户端?我需要一个特殊的多播 IP 地址吗?
- python - Python,函数,这里发生了什么?如果 lst1[index] != lst2[len(lst2) - 1 - index]
- javascript - 在 Node 中设置 AWS 开发工具包凭证
- ios - 我的 TableView 只列出了 itemArray 中的最后一项?
- amazon-web-services - aws Lex UI 不显示来自其他帐户的 lambda 函数
- django - Django 查询集获得前 3 名用户
- python - repo.checkout() :您对以下文件的本地更改将被 checkout 覆盖
- flutter - 谷歌使用 Flutter/Firebase 登录时如何获取 refreshToken
- javascript - 如何将事件侦听器添加到按钮元素