Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 为了以不同的查询定义采用不同的参数的方式实现MS Access报告,需要采取哪些步骤?_Sql_Vba_Ms Access_Ms Reports - Fatal编程技术网

Sql 为了以不同的查询定义采用不同的参数的方式实现MS Access报告,需要采取哪些步骤?

Sql 为了以不同的查询定义采用不同的参数的方式实现MS Access报告,需要采取哪些步骤?,sql,vba,ms-access,ms-reports,Sql,Vba,Ms Access,Ms Reports,在我的工作桌面上,我有 -Microsoft Office Professional Plus 2013 Access 我的任务是创建一个带有Access DB的MS Access应用程序 我的应用程序中有MS Access报告 MS Access报告的记录源与MS Access查询定义相关联 ,而且,所说的MS Access查询定义采用了一个参数,我将其命名为idArg(类型为Double) 但是,在MS Access报告中,我还有一个列表框,它与另一个MS Access查询定义关联,该定义采

在我的工作桌面上,我有

-Microsoft Office Professional Plus 2013 Access

我的任务是创建一个带有Access DB的MS Access应用程序

我的应用程序中有MS Access报告

MS Access报告的记录源与MS Access查询定义相关联

,而且,所说的MS Access查询定义采用了一个参数,我将其命名为idArg(类型为Double)

但是,在MS Access报告中,我还有一个列表框,它与另一个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 Access报告,我必须采取哪些步骤才能将CInt(Me.IdV2.Caption)正确分配给“idArg2”?

只需删除查询参数即可。只需根据原始查询生成报告

然后,要过滤报告,请向其传递一个“where”子句

因此:

至于另一份报告,我们将:

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子句。因此,您的查询将没有参数

Thx,但我想问的是一个单一MS Access报告需要多个参数参数的情况(事实上,更具体地说,我的单一MS Access报告需要一个参数作为它自己的QueryDef,&所述单一MS Access报告中的一个列表框有另一个与之关联的QueryDef,它需要另一个参数。)为参数设置两个独立的位置是困难的。删除所有参数,然后只向查询传递一个简单的where子句。正是这些无处不在的参数在这里造成了困难。您应该能够过滤报告,而不必过滤原始查询。这样,您就可以自由地编写任何想要的过滤器。但是,因为您有查询,然后有一个报告,您可能会考虑重写原始查询生词SQL。但是,如果可能,请通过where子句。
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