[英]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.