简体   繁体   English

如何在Access表单中为Access报表上的嵌入式查询设置参数?

[英]How do I set parameters for an embedded query on an Access report from an Access form?

I have an existing Access report that runs off a Query. 我有一个基于查询的现有Access报告。 In the existing report I have the parameters set with brackets; 在现有报告中,我使用括号将参数设置为; [CSRName], [StartDate], and [EndDate]. [CSRName],[StartDate]和[EndDate]。 I have those parameters being filled form a form using the VBA below; 我使用下面的VBA将这些参数填写在表格中;

All of this works just fine. 所有这些都很好。 My problem is this; 我的问题是 I have this query counting the total number of errors a CSR makes. 我有这个查询,计算CSR造成的错误总数。 I can easily display in the report the total number of errors. 我可以轻松地在报告中显示错误总数。 What I'd like to do is have another textbox on the report that shows the total number of completed items by the CSR. 我想做的是在报告上有另一个文本框,其中显示了CSR完成的项目总数。 In order to do this I need to embed the Control Source for the textbox with another query. 为此,我需要将文本框的“控制源”嵌入到另一个查询中。 I have that query written and it works outside the form. 我已经编写了该查询,并且该查询在表单外起作用。 What I need to do though is pass the same parameters that I am using to generate the report into this embedded query on the report. 不过,我需要做的是将与生成报表相同的参数传递给报表上的该嵌入式查询。 I can't figure out how to do that. 我不知道该怎么做。 I can pass the parameters to the report itself, and it works fine, but trying to do the same won't pass the parameters to the embedded query in the report. 我可以将参数传递给报表本身,并且可以正常工作,但是尝试执行相同操作不会将参数传递给报表中的嵌入式查询。 It keeps popping up an input box and asking me to give it the variables. 它不断弹出一个输入框,并要求我为其提供变量。

I assumed I could treat the embedded query the same that I could the query the report is based off, so I used the same process to try to pass the parameters to it as well, but it did not work. 我假设我可以像对待报表所基于的查询一样对待嵌入式查询,因此我也使用相同的过程尝试将参数传递给它,但是它没有用。

Private Sub RunQuery_Click()

    DoCmd.SetParameter "CSRName", Me.CSRNameCB
    DoCmd.SetParameter "StartDate", "#" & Me.StartDate & "#"
    DoCmd.SetParameter "EndDate", "#" & Me.EndDate & "#"

    DoCmd.OpenReport "rpt_CSRErrorTracking", acViewPreview

End Sub

What I need is the method to pass the parameters from the form to both the query that the report is based off, and the query embedded in the report itself. 我需要的是将参数从表单传递到报表所基于的查询以及嵌入在报表本身中的查询的方法。

How about having the queries that the report and report field are based on store the "link" to the form's fields something like this (query by form concept)... 如何让报表和报表字段基于的查询存储到表单字段的“链接”,就像这样(按表单概念查询)...

In the query's criteria for an appropriate field: 在查询条件中的适当字段中:
= [Forms]![MyForm]![CSRNameCB] = [表单]![MyForm]![CSRNameCB]

And: 和:
Between [Forms]![MyForm]![StartDate] And [Forms]![MyForm]![EndDate] 在[Forms]![MyForm]![StartDate]和[Forms !! [MyForm]![EndDate]之间

And then on the form that opens the report you don't have to set any parameters at all. 然后,在打开报表的表单上,您根本不需要设置任何参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从报表中导出查询以使用参数访问Excel - Export query from a report in access to excel with parameters 如何在Access中进行分层\\级联查询\\报告? - How do I make hierarchical\cascading query\report in Access? 如果需要从多个表单加载依赖报表,如何将参数传递到Access查询的内部WHERE子句? - How do you pass parameters into an inner WHERE clause of an Access query if the dependent report needs to be loaded from multiple forms? 如何根据相关表中的值过滤Access报告/查询? - How do I filter an Access report/query based on values from a related table? 如何即时编辑 Access 报告? - How do I edit an Access report on the fly? MS Access Report RecordSource 是一个带参数的查询。 如何传递参数值? - MS Access Report RecordSource is a query with a parameter. How do I pass a parameter value? 我如何通过 MS 访问中的查询制作 MS 访问表单 - How can i make a MS access form from query in MS access 访问多个查询参数的表单字段 - Access form fields for multiple Query parameters 访问查询 - 在查询设计 GUI 中,如果 null,我如何设置总和以返回零? - Access query - in Query Design GUI how do I set a sum to return zero if null? 根据访问表单中的用户输入生成报告 - Generating Report from User Inputs in Access Form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM