传递查询参数子报表 [英] Passing Query Parameter to Sub-Report
问题描述
这是一个很长的时间,因为我曾与MS Access和我不知道如果我这样做是正确的。
It has been a long time since I have worked with MS Access and am not sure if I am doing this right.
我有绑定到用户名的单一列表查询报表。上的用户名的报告基团和具有一个子报告中的细节,是一个图表
I have a Report bound to a query of single list of user names. The report groups on the user name and has a sub-report in the detail that is a chart.
子报告/图表是基于接受的用户名的参数的查询。由于副报告未绑定我需要通过从主报告细节onload事件的用户名参数下降到子报告,从而进入下面的查询。
The sub-report/chart is based on a query that accepts a parameter of the user name. Since the sub report is not bound I need to pass the user name parameter from the main report detail onload event down to the sub-report and thus into the underlying query.
我不理解如何做到这一点,甚至如果我的做法是合理的。
I am not understanding how to make that happen or even if my approach is sound.
(PS我最初发布的超级用户,但看到没有多少人使用该网站。)
(p.s. i originally posted on "Super User" but see not many people use that site.)
感谢您的帮助
推荐答案
要获得子报表,他们应该被绑定到一个记录源(表或查询)的全部利益,并使用链接主字段子窗体/子报表控件为同步与父记录的报表数据code>和
链接子字段
属性。
To get the full benefit of subreports they should be bound to a recordsource (table or query) and use the Link Master Fields
and Link Child Fields
properties of the Subform/Subreport control to "sync" the subreport data with the parent record.
假设你有一个[网友]表
Say you have a [Users] table
userID
------
Gord
Tim
和[UserTraffic表
and a [UserTraffic] table
userID trafficDate downloadMB
------ ----------- ----------
Gord 2013-04-26 366
Gord 2013-04-25 442
Tim 2013-04-26 890
Tim 2013-04-25 212
您的主报告[UserReport]必然会[用户],并包含基于报表中的报表控件[UserTraffic_subreport]
Your main report [UserReport] is bound to [Users] and contains a subreport control based on the report [UserTraffic_subreport]
当您使用该报告中的子窗体/子报表控件在主窗体......
When you use that report in your Subform/Subreport control on your main form...
......一定要设置链接主字段
和链接子字段
属性...
...be sure to set the Link Master Fields
and Link Child Fields
properties...
...所以您的报告会出来这样的:
...so your report will come out like this:
请注意,这个例子不需要VBA code在所有。
Note that this example required no VBA code at all.
添加图表的报告时,同样的原则也适用。下面的报表显示用户流量按日期,所以记录源的主报告
The same principles apply when adding a chart to a report. The following report displays user traffic by date, so the Record Source for the main report is
SELECT DISTINCT trafficDate FROM UserTraffic ORDER BY trafficDate;
该报告使用子窗体的图表控件,而不是/子报表控件...
The report uses a Chart control instead of the Subform/Subreport control...
......与图表控件的属性...
...and the properties of the Chart control are...
结果报告如下
这篇关于传递查询参数子报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!