View Full Version : Passing result of main report query to sub report as parameter


pompey1
06-19-2008, 05:45 AM
Hi,
I am new to Access (so please bear with me http://help.lockergnome.com/office2/modules/Forums/images/smiles/icon_smile.gif). I'm building a report in which I need to embed a sub-report. The main report calls a query to get it's data, and i need to pass a value retrieved in that query through to the sub-report. That parameter then becomes a part of the WHERE clause in the query for the sub-report. In my .MDB I need to keep it very simple, so I only have tables, queries and reports - no Macro/prcedure/form/etc.

I have two questions:
- how do i do it?
- how do i identify the parameter in the sub-query?

Thanks a lot, Dave

llkhoutx
06-19-2008, 10:16 AM
If the value retrieved in not displayed on your report, put it on the report and then use that field as the "Link Master Field" property of the subreport. Set the "Link Child Field" property appropriately to a field on the subreport.

pompey1
06-20-2008, 01:25 AM
Hi, thanks for the help.

Unfortunately I'm using the Dutch version of Access 2003, i can't find any Subreport property called anything remotely like Link Master Field or Link Child Filed (or the Dutch translations). What position does it appear in the menu? Or are you using Access 2007?

When I use the wizard to add the subreport, it does give me the option to link a field from the main report with a field with the subreport, but if I do this then the subreport always appears empty even though the data is match-able. If I do not match the fields then I get a complete list of the child table on every page, understandably. Is there perhaps a reason why the matching fields would not generate the correct results? When I run the sub-report on it's own it gives me the correct results, but just doesn't match them on the main report.

Thanks, Dave

llkhoutx
06-20-2008, 07:21 AM
To find the property, select the edge of the subreport, not the the upper left corner, and you'll find that the properties button will display the properties of the subreport.

boblarson
06-20-2008, 07:27 AM
To find the property, select the edge of the subreport, not the the upper left corner, and you'll find that the properties button will display the properties of the subreport.

Here's a visual on selecting the subreport container control (see screenshot within this):
http://www.btabdevelopment.com/main/QuickTutorials/Easywaytorememberhowtoreferencesubforms/tabid/76/Default.aspx

pompey1
06-23-2008, 12:38 AM
Hi list,

Well I have now managed to locate the correct properties, thanks for you guys. I can now see that the main and sub-report are coupled as I want - with the main report field linked to the sub-report field. But the sub-report still always appears blank when I run it even though the data is coupled on the database. There is even referential integrity on the relationship between the tables, I can be 100% sure that the data should produce a few rows in the subreport. Any idea why I still may not see any data on the sub-report.

(By the way, I tried deleting and recreating the subreport without any field matching, and on every page I got a full print out of the table read in the subreport so I know that that works OK).

Thanks,
Dave

boblarson
06-23-2008, 05:39 AM
You might need to post the db (see here for how: http://www.access-programmers.co.uk/forums/showthread.php?t=140587 )