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

Proble creating a progressive sum and place it at pre-defined place on page (bottom)

edited March 2003 in End User
Hi,
I'm having a huge problem, and any help is more than appreciated...
The problem is:
I want to create a bill report. The data are pulled from a database.
The report will be printed on pre-printed paper where on the bottom of each
page sould be the progressive sum of a column.
So on the last page there should be the summary of all pages.
I use a DBcalc component with DBcalcType=dcSum and i place it on the page
footer.
The problem is that the report seems to understand that the page has change
only when the first line of the next page is printed.
That results on a miscalculation of the proggressive summary because it has
add the first line of the next page.
Is there a way to avoid it?
I have tried to use the ppSummaryBand instead of the footerBand but it seams
to me that there is no way to place it in a predifined place on a page.

Thank you very much for your help

Kindly regards
Nemos

Comments

  • edited March 2003
    The problem you are running into most likely, is that the calculation you
    have is including the record which prints on the top of the subsequent page.
    What happens when the report is generating is that the band tries to print
    at the bottom, if it doesn't fit, then it must print at the top of the next
    page. In order to determine if a dynamic height band can fit on a page, it
    must generate. This includes firing the OnCalc events, even though it will
    be determined later that the band will not be able to fit on the current
    page. In order to workaround this, you can code the transfer of the
    calculation to a label in the footer. Place a TppVariable in the detail
    band. In its OnCalc event handler, place the calculation to sum the value in
    the pipeline.

    Value := Value + plOrders['AmountPaid'];

    Then use the DetailBand.AfterGenerate event in order to find out if the band
    could successfully generate. If it did attempt to generate and is not out of
    space, then transfer the variable's value to the label.

    procedure TForm1.ppDetailBand1AfterGenerate(Sender: TObject);
    begin
    if not(ppDetailband1.OutOfSpace) then
    ppLabel5.Caption := ppVariable1.Value;
    end;

    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited March 2003
    Hi again and thank you for your quick responce.
    I have tried it but it doesn't work.
    It's still adding the record which prints on the top of the subsequent page.
    But i tried something else:

    procedure TDoneBillFrm.ppVariable1Calc(Sender: TObject;
    var Value: Variant);
    begin
    Value:=Value+FcostPipeline.GetFieldAsDouble('oblAmount');
    end;

    procedure TDoneBillFrm.ppFooterBand9AfterGenerate(Sender: TObject);
    begin
    if not (ppFooterBand9.OutOfSpace) then

    ppLabel144.Caption:=ppVariable1.Value-FcostPipeline.GetFieldAsDouble('oblAmo
    unt');
    end;

    The problem now is that in the last page it misses the last value ... (it's
    logical)
    any idea ?

    best regards and many thanks
    Nemos

  • edited March 2003
    Another way to do it is to let the report generate and alter the output.
    Because bands sometimes have to generate to check for space used, but don't
    create output, then you can leverage the OnDrawCommandCreate event of a
    component to know that the report created output. Here is an example which
    works this way. I didn't free the variable draw commands, as the report
    engine doesn't expect this to happen, so I cleared the text out instead and
    left them as objects on the page.
    http://www.digital-metaphors.com/tips/RunningSummaryTotalInFooter.zip

    If you use any KeepTogether action, you can dispose of the above technique,
    but use a DBCalc instead. The KeepTogether logic should track the correct
    value in the DBCalc in the footer. When KeepTogether is not in use, then you
    will need to track the value similar to the demo.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited March 2003
    Cheers
    I'll try it
    thanks very match.

This discussion has been closed.