Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
651 views
in Technique[技术] by (71.8m points)

ms access - Passing Query Parameter to Sub-Report

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.

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.

(p.s. i originally posted on "Super User" but see not many people use that site.)

Thanks for the help

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

Your main report [UserReport] is bound to [Users] and contains a subreport control based on the report [UserTraffic_subreport]

subreport1.png

When you use that report in your Subform/Subreport control on your main form...

mainreport.png

...be sure to set the Link Master Fields and Link Child Fields properties...

properties.png

...so your report will come out like this:

preview.png

Note that this example required no VBA code at all.

Edit

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...

design.png

...and the properties of the Chart control are...

properties.png

The resulting report looks like this

preview.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...