subreports

R

Robert

I have a report with two sub reports that I’m trying to do some basic math
with. After researching for a solution I thought I found a solution.

Stage 1
If the subreport is called Sub1, and the text box is txtTotal, put the text
box on your main report, and start with this Control Source:
=[Sub1].[Report].[txtTotal]

Stage 2
Check that it works. It should do if there are records in the subreport. If
not, you get #Error. To avoid that, test the HasData property, like this:
=IIf([Sub1].[Report].[HasData], [Sub1].[Report].[txtTotal], 0)

Stage 3
The subreport total could be Null, so you might like to use Nz() to convert
that case to zero also:
=IIf([Sub1].[Report].[HasData], Nz([Sub1].[Report].[txtTotal], 0), 0)

The problem I have is I get #error messages when no sub report exists. If a
subreport does exist things work fine. I have tried both the hasdata and NZ
in steps 2 and 3 with no luck. The only difference I have found is I’m using
! Between fields not a . When I use a . I get name error. Again data is
pulling from subreports if they exist so I know the location is fine. Any
help would be appreciated.
 
S

storrboy

I have a report with two sub reports that I'm trying to do some basic math
with. After researching for a solution I thought I found a solution.

Stage 1
If the subreport is called Sub1, and the text box is txtTotal, put the text
box on your main report, and start with this Control Source:
=[Sub1].[Report].[txtTotal]

Stage 2
Check that it works. It should do if there are records in the subreport. If
not, you get #Error. To avoid that, test the HasData property, like this:
=IIf([Sub1].[Report].[HasData], [Sub1].[Report].[txtTotal], 0)

Stage 3
The subreport total could be Null, so you might like to use Nz() to convert
that case to zero also:
=IIf([Sub1].[Report].[HasData], Nz([Sub1].[Report].[txtTotal], 0), 0)

The problem I have is I get #error messages when no sub report exists. If a
subreport does exist things work fine. I have tried both the hasdata and NZ
in steps 2 and 3 with no luck. The only difference I have found is I'm using
! Between fields not a . When I use a . I get name error. Again data is
pulling from subreports if they exist so I know the location is fine. Any
help would be appreciated.

Your controlsource is getting pretty complex.
I don't understand why the subreport would not be there. If it's not I
would guess that the sub report control has a SourceObject of ""?
You could try to test for this...

=IIF([Sub1].SourceObject="","", IIf([Sub1].[Report].[HasData],
Nz([Sub1].[Report].[txtTotal], 0), 0))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top