Subreport with 0 records gives error

O

Octavee Uhl

Hi,

I have a problem with a subreport in a report in MS Access 2002.
I want to add up records in a subreport and add this values in the main
report.

The problem comes in when the subreport does not have any records in it.
Then I get an error message in the field in the main report.
I tried an IIF function, but it does not evaluate like I need it. I tried a
Nz function, but did not work for me. What is the best way to integrate
this?

Thanks
Octavee Uhl
 
A

Allen Browne

Yes, any attempt to refer to the non-existent text box in the subreport
generates an error. You can avoid this by testing the HasData property of
the report in the subreport control.

The reference will look something like this:
=IIf([sub1].[Report].[HasData], Nz([sub1].[Report].[text1],0), 0)
where "sub1" is the name of the subreport control, and "text1" is the name
of the text box on the subreport.
 
S

Steven Warren via AccessMonster.com

I remember having this problem and trying both the iff and Nz and getting
no where but finally using the Iff did work it was how I was writing it.

My example: I entered below in the control source on my main report.

=IIf(IsError([rptLaborOrderEstimate].[Report]![txtTotalLaborSalePrice]),0,
[rptLaborOrderEstimate].[Report]![txtTotalLaborSalePrice])

rtpLaborOrderEstimate is a subreport
txtTotalLaborSalePrice is the name of the control on my main report.

Hope it helps
 
O

Octavee Uhl

Thanks Allen,

that worked great.

Octavee

Allen Browne said:
Yes, any attempt to refer to the non-existent text box in the subreport
generates an error. You can avoid this by testing the HasData property of
the report in the subreport control.

The reference will look something like this:
=IIf([sub1].[Report].[HasData], Nz([sub1].[Report].[text1],0), 0)
where "sub1" is the name of the subreport control, and "text1" is the name
of the text box on the subreport.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Octavee Uhl said:
I have a problem with a subreport in a report in MS Access 2002.
I want to add up records in a subreport and add this values in the main
report.

The problem comes in when the subreport does not have any records in it.
Then I get an error message in the field in the main report.
I tried an IIF function, but it does not evaluate like I need it. I tried
a Nz function, but did not work for me. What is the best way to integrate
this?

Thanks
Octavee Uhl
 
Top