Subreport Expressions

D

deiopajw

I have a subreport called subrpt_abc
Its embedded in a report called rpt_main.

The subreport has a calculated field called TotalACost.

The main report also has a calculated field called TotalPanelCost.

I wanted to be able to add these two values together. It only seems to work
when I create a Grand Total field in the subreport only.
However the expression I used does not work. I used:
=Reports!rpt_main!TotalPanelCost!+TotalACost

Note: when my mouse cursor exits the Control source field, the expression
all of a sudden has brackets: ie
=[Reports]![rpt_main]![TotalPanelCost]!+[TotalACost]
I think these brackets cause the error in giving me the required total value
amount.
Why are these brackets appearing?
 
A

Allen Browne

Presumably TotalACost is a text box in the Report Footer section of the
subreport.

Put a text box on the main report, and set its Control Source to:
=IIf([subrpt_abc].[Report].[HasData],
Nz([subrpt_abc].[Report].[TotalACost],0), 0)

When there are no matching records in the subreport, nothing shows and so
referring to the non-existent text box in the subreport causes an error. The
expression above solves that by testing the HasData property of the report
in the subreport control.

It is possible that the total could be Null, so it solves that with Nz().

Access can misunderstand the data type of calculated text boxes. To solve
that, set the Format of these text boxes to Currency (or General Number or
something.)

If you still get #Error, there is a problem with the name. Check that:
a) the calculated text boxes do not have the same Name as one of the fields,
and
b) your expression uses the name of the subreport control (which may be
different from the name of the report it contains, i.e. its SourceObject.)
 

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