How to update value in Main report control from subreport

  • Thread starter Thread starter Sunny
  • Start date Start date
S

Sunny

I have one main report say TestReport and one sub report say TestSubReport.
In testreport I have one text control txtTotal (client total sales) along
with several other controls. TestReport is grouped by Area Office and then
Client Id. On client id footer I have added testsubreport.

I assign txtTotal = 0 in client header and I want to calculate txtTotal in
subreport detail print event. I am using
me.Parent.txtTotal = me.Parent.txtTotal + SalesAmount

But I get 0 everytime as a client total sales. What am I missing here?
 
Sunny said:
I have one main report say TestReport and one sub report say TestSubReport.
In testreport I have one text control txtTotal (client total sales) along
with several other controls. TestReport is grouped by Area Office and then
Client Id. On client id footer I have added testsubreport.

I assign txtTotal = 0 in client header and I want to calculate txtTotal in
subreport detail print event. I am using
me.Parent.txtTotal = me.Parent.txtTotal + SalesAmount

But I get 0 everytime as a client total sales. What am I missing here?


There's probably some kind of timing issue with that
approach, but it doesn't matter what the problem is because
you can not reliably use event procedure code to calculate a
total across multiple records (there are many reasons why
report events can be triggered multiple times and in almost
any orde)r.

Let the subreport calculate the total by using a text box
(in the subreport's Report Footer section) named
txtSubTotalSales with the expression:
=Sum(SalesAmount)

Then the main report can display the subreport's total by
using a text box with the expression:

=subreport.Report.txtSubTotalSales

If it's possible that a subreport might not have any records
to total, then use this expression instead:

=IIf(subreport.Report.HasData,
subreport.Report.txtSubTotalSales, 0)
 
Thanks Marshall.

What will be the exact syntax for my report name and subreport name. Should
I put this code in controlsource property of txtTotal control or can I write
in ClientId footer format code?
 
Sunny said:
What will be the exact syntax for my report name and subreport name. Should
I put this code in controlsource property of txtTotal control or can I write
in ClientId footer format code?


All of the expressions I posted are text box control source
expressions, you do not (indeed can not) use them in an
event procedure.

Replace the "subreport" in my expressions with the name of
the subreport **control** (on the main form). This name may
or may not be the same as the name of the report object that
it is displaying. If the control name has spaces or other
funky characters in it, then enclose it in square brackets.
E.g. [My test SubReport]

The name of the main report is not used in these
expressions.
--
Marsh
MVP [MS Access]

 
Back
Top