Home Subreports

Grand Total using variable val's from main & subreport

edited March 2007 in Subreports
Hi,

I have checked all the other posts re- global variables but can't see
anything that matches my problem. I have a report where the summary band
prints totals based on values in the detail band of the main report,
followed by a subreport that prints 2 total values from another data
pipeline, followed by a grand total (see below).

mainreport.var1 $100.00
mainreport.var2 $200.00
mainreport.var3 $25.00
subreport.var1 $150.00 Variable1 = $150.00
subreport.var2 $120.00 Variable2 = $120.00
----------------------------
grandtotal $325.00

The grandtotal adds up the values of the main report variables but does not
include the values of the global variables I have set. The 2 variables that
are returned from the subreport (Variable1 & Variable2 above) print in the
summary of the main report correctly however they will not add into the
grand total no matter what I do. The calc order is correct, I tried changing
the Z order of the summary band as well.

Following a tech tip example (RAPGrandTotalInHeader), this is how it is
setup. In the module section of the main report I have declared 2 global
variables as

Var
gVariable1: TppVariable;
gVariable2: TppVariable;

and then in the GlobalOnCreate
gVariable1 := Variable1;
gVariable2 := Variable2;

In my subreport I increment the value of gVariable1 & gVariable2 at the same
time as I calc the subreport values.

gVariable1.Value := gVariable1.Value + amount_1
gVariable2.Value := gVariable2.Value + amount_2

These values then print correctly on the main report as Variable1 and
Variable 2 but do not get included in the grand total. The calc order has
them prior to the grand total calc. If these variables print the correct
values, why won't a calc that follows them in the calc order include them ?

I have spent a lot of time so far to no avail. Any ideas ?

Comments

  • edited March 2007
    Hi Rick,

    What component are you using for the Grand Total? If you are using a DBCalc
    component, try replacing it with a TppVariable instead and add up the value
    manually in code. You could stay with the direction you are going and add
    up all the variables at the end, or you could link a single global variable
    from the subreport to the grand total variable and update it's value in its
    OnCalc event while the subreport is generating.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited March 2007
    Hi Nico,

    I was already using a TppVariable and adding the value in code. In the end I
    found the problem was that the subreport was type 'Child'. When I changed it
    to 'Fixed' it worked fine (the subreport will only ever output 2 lines). Not
    sure why the child version wouldn't work but at least it now works.

    Rick.

This discussion has been closed.