Accessing subreport controls in Nodata case

User avatar
silverback
5StarLounger
Posts: 774
Joined: 29 Jan 2010, 13:30

Accessing subreport controls in Nodata case

Post by silverback »

I have a main report which contains two subreports, Leavers and Starters. Each subreport contains, in its Report Footer, a textbox control which sums a column (wte). I have made this sum conditional so that, if the report has no data, the sum is set to zero. This is the expression I used :
IIf(Report.Hasdata, Sum(wte), 0)
This works OK when either report is run free standing.

The main report needs to calculate the difference between the two subreport sum controls, taking the smaller from the larger (it tests for if they're equal and produces an appropriate output).

This is working except for the no data case with one or both of the reports. In this situation, the calculated field displays #Error. By conditionally setting the subreport sum controls to zero, I thought that, in the main report, it would be still possible to access the subreport control in the nodata case; this seems not to be true.
Here's the calculation :

Code: Select all

=IIf([rptLeaversSub].[Report]![txtSumLeavers]=[rptStarters].[Report]![txtSumStarters],"Overall wte remains the same",IIf([rptLeaversSub].[Report]![txtSumLeavers]>[rptStarters].[Report]![txtSumStarters],"Net Loss to wte of " & ([rptLeaversSub].[Report]![txtSumLeavers]-[rptStarters].[Report]![txtSumStarters]),"Net gain in wte of " & ([rptStarters].[Report]![txtSumStarters]-[rptLeaversSub].[Report]![txtSumLeavers])))
Can these subreport controls be accessed in the main report in the no data cases or does the calculation have to test explicitly for no data cases?

Thanks
Silverback

User avatar
HansV
Administrator
Posts: 78487
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Accessing subreport controls in Nodata case

Post by HansV »

If there are no data, the subreport simply isn't there in print preview or print mode, so you can't refer to a control on it. You'll have to test for no data in the expression on the main report.
Best wishes,
Hans