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

Calc error on last page.

edited February 2004 in General
Hi all,
i have created a report where in the detail band i print two rows for each
record of the dataset; the first row contain a number.

If i print a preview of this report and i go to the last page using the last
button in the preview window and the first detail row contain a number, the
total of all numbers in the page, don't contain the number of the first row.

If I go to the previous page and then I go to the next page ( the last page)
the same total is correct.

Please note that i don't use the dbcalc component to sum the value, but a
variable that is calculated in the detailafterprint event with this
statement:

Variable1.value := Variable1.value + Dataset['NUMBER'];

Thanks in advance.

Massimo.

Comments

  • edited February 2004
    Hi Massimo,

    You do not want to make calculations inside the DetailBandAfterPrint event
    as this event fires many times for each traversal. Instead you will want to
    place another variable inside your detail band and make the same calculation
    you have below inside the new variable's OnCalc event.

    ----------------------------------------------------------------------
    TECH TIP: Performing Calculations
    ----------------------------------------------------------------------

    Calculations can be done either on the data access side
    or within ReportBuilder.

    When designing reports there are always decisions to be made as to
    how much processing to do on the data side versus the report side.
    Usually doing more on one side can greatly simplify the other. So it is
    often a personal choice based on the power and flexibility of the data
    and report tools being used.


    DataAccess
    ----------

    a. Use SQL - using SQL you can perform many common calculations:

    example: Select FirstName + ' ' + LastName As FullName,
    Quantity * Price AS Cost,


    b. Delphi TDataSets enable you to create a calculated TField object
    and use the DataSet.OnCalcFields event

    c. Perform any amount of data processing, summarizing, massaging
    etc. to build a result set (query or temp table) to feed to the report.


    ReportBuilder
    -------------

    Calculations in ReportBuilder are performed primarily using
    the TppVariable component.

    a. Set the Variable.DataType

    b. Code the calculations using the Variable.OnCalc event.

    c. Use the Timing dialog to control the timing of the OnCalc event.
    To access the Timing dialog, right click over the Variable
    component and select the Timing... option from the speed menu.

    d. Set the LookAhead property to True, when you need to display
    summary calculations in the title, header, group header, etc.

    e. To perform calculations based on the results of other
    calculations use the Calc Order dialog of the band. To access
    the Calc Order dialog, right click over the Band component
    and select the Calc Order... option from the speed menu.


    By using TppVariable components ReportBuilder will take care of caching
    intermediate results of accumlated calcs that cross pages.

    There are a number of calculation examples in the main demos.dpr
    project.

    ---

    Additional Notes:

    1. Do NOT use Band.BeforePrint or Band.AfterPrint. These events fire
    multiple times and therefore should not be used for calculations.

    2. Do NOT store results in variables that exist outside of the reports.
    For example - form level variables.


    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2004
    Hi Nico and thanks for the answer.

    Now if i use a tppvariable and i insert in the oncalc event this statement

    value := value + Dataset['NUMBER'];

    the total contain the first row of the next page when i print it in the
    footer band; this problem is visible on each page.

    Please note that i use the beforeprint event in the footer band to assign
    to another tppvariable the value of the detail tppvariable for print it:

    footervar.value := detailvar.value;

    There is a solutions to print in the footer band a total without sum the
    first number of the first row of the next page ?


    Thanks in advance.

    Massimo.




    "Nico Cizik (Digital Metaphors)" wrote
    to
    calculation
  • edited February 2004
    Hi Massimo,

    If you are making a sum in the Footer band with a dynamic height detail
    band, this is a limitation of ReportBuilder. The only way around this
    limitation is to either use a group footer rather than the page footer or
    keep a static height detail band.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2004
    Hi Nico,
    if i use a group footer to salve this limitation, how i can break the group
    as a classic footer band on each pages ?

    Thanks in advance.

    Massimo.
  • edited February 2004
    Hi Massimo,

    The following example might help you.

    http://www.digital-metaphors.com/tips/GroupFooterOnEveryPage.zip

    --
    Best Regards,

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