Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Field in one subreport depends on data in another

edited February 2012 in General
?I've got a report with two subreports in the detail band. The first
subreport contains calculated fields that depend on a field in the second
subreport which is below the first in the report.

The variable fields are in the footer of the first subreport. I can seem
to access the fields in the detail of the first subreport, and I have a
dbCalc field that gets me the right summation. However, if I have to sum
fields that are in the detail section of the SECOND subreport, I'm getting
back data that's either zero or applies to the previous item in the main
report. In other words, it seems to be an event-sequencing issue. Is there
a way I can work around this? Or, perhaps more to the point, what am I
doing wrong?

Lane C.
NW Software

Lane C
NW Software

--- posted by geoForum on http://www.newswhat.com

Comments

  • edited February 2012
    Hi Lane,

    Is this a two-pass report and are you taking advantage of the Lookahead
    feature?

    Accessing the value of a DBCalc can be difficult as it is calculated
    internally. The best option would be to place a TppVariable inside the
    detail of the second subreport and in its OnCalc, update the value in
    the first subreport.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2012
    Nico,
    I'm still not getting anywhere. It is a two-pass report, and I've tried
    the lookahead. Still getting the value from the previous detail.

    Here's how the report is structured:

    --------------------------------
    Header
    ----------------------------------
    Group header
    -------------------------------\
    Detail, containing
    ----------------------------------------------
    subreport1
    Detail Amount
    Amount ...
    ----------------------------------
    Summary Total of above amounts (this works)
    Total Payments (from subreport2)
    Balance (Total sr1 - Total sr2)
    ------------------------------------------------------------
    Subreport2
    Detail Payment
    Payment...
    ------------------------------------------------------
    I tried making a summary to Sr2 & putting a DBCalc in it summing the
    payments, but can't seem to transfer that sum back to a field in the
    summary of sr1.
    Help... I'm not getting much from the PDF manual ...

    Lane C.
    NW Software
    ******************
  • edited February 2012
    Nico,
    Here's something else I noticed. I put a dbCalc summing the payments in
    a summary to subreport2. In its OnCalc, I would set the variable in the
    summary of subreport1. In the debugger, I can see the value reset; but
    before the variable actually prints, "something" sets it back to zero
    again. What's happening?

    Thanks for the help,

    Lane C.
    NW Software
    ************************
  • edited February 2012
    ?Nico,
    I'm still not getting anywhere. It is a two-pass report, and I've tried
    the lookahead. Still getting the value from the previous detail.

    Here's how the report is structured:

    --------------------------------
    Header
    ----------------------------------
    Group header
    -------------------------------\
    Detail, containing
    ----------------------------------------------
    subreport1
    Detail Amount
    Amount ...
    ----------------------------------
    Summary Total of above amounts (this works)
    Total Payments (from subreport2)
    Balance (Total sr1 - Total sr2)
    ------------------------------------------------------------
    Subreport2
    Detail Payment
    Payment...
    ------------------------------------------------------
    I tried making a summary to Sr2 & putting a DBCalc in it summing the
    payments, but can't seem to transfer that sum back to a field in the
    summary of sr1.
    Help... I'm not getting much from the PDF manual ...

    Lane C.
    NW Software
    ******************

    Lane C
    NW Software

    --- posted by geoForum on http://www.newswhat.com
  • edited February 2012
    Hi Lane,

    I would not recommend using a DBCalc to make any other calculations.
    Use a TppVariable instead. Perhaps, store the value calculated by the
    variable in a class variable and then (during the second pass) access
    that value for the first subreport.

    Variable.OnCalc event of the second subreport
    begin
    if Report.FirstPass then
    FValue := FValue + Subreport2.Report.Datapipeline['MyField'];
    end;

    Variable.OnCalc event of first subreport
    begin
    if Report.SecondPass then
    Value := FValue;
    end;



    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.