Totals in group footer incorrect as page breaks
I have a report with a detail band containing transactions from a single
table, and a group footer that totals the various types of transactions
across the groupfooter. It looks like this:
DetailBand ===================
Tran1 ReceiptNo TranAmt
Tran2 ReceiptNo TranAmt
Tran3 ReceiptNo TranAmt
Groupfooter ==================
TotalType1 TotalType2 TotalType3
===========================
The DetailBand is hidden at run time so the output is like this:
ReceiptNo TotalType1 TotalType2 TotalType3
ReceiptNo TotalType1 TotalType2 TotalType3
ReceiptNo TotalType1 TotalType2 TotalType3
The transactions are receipt detail lines and report is a banking summary
giving one line per receipt broken down by payment type across the page,
basically like a ledger. The detailband contains 1 to many lines from the
receipt.
The totals in the Groupfooter are variables and have datatype of double.
My problem is:
The first line on each page has a total of double the actual transaction
value.
I do the calculation in DetailBandBeforeGenerate, this looks at what type
the transaction is and adds it to the appropriate total in the footer. The
footer is reset when the TranNo changes. The beforegenerate event fires
twice on a page break.
We are on D7 and RB 11.01, any suggestions greatly appreciated.
Thanks
Bruce.
table, and a group footer that totals the various types of transactions
across the groupfooter. It looks like this:
DetailBand ===================
Tran1 ReceiptNo TranAmt
Tran2 ReceiptNo TranAmt
Tran3 ReceiptNo TranAmt
Groupfooter ==================
TotalType1 TotalType2 TotalType3
===========================
The DetailBand is hidden at run time so the output is like this:
ReceiptNo TotalType1 TotalType2 TotalType3
ReceiptNo TotalType1 TotalType2 TotalType3
ReceiptNo TotalType1 TotalType2 TotalType3
The transactions are receipt detail lines and report is a banking summary
giving one line per receipt broken down by payment type across the page,
basically like a ledger. The detailband contains 1 to many lines from the
receipt.
The totals in the Groupfooter are variables and have datatype of double.
My problem is:
The first line on each page has a total of double the actual transaction
value.
I do the calculation in DetailBandBeforeGenerate, this looks at what type
the transaction is and adds it to the appropriate total in the footer. The
footer is reset when the TranNo changes. The beforegenerate event fires
twice on a page break.
We are on D7 and RB 11.01, any suggestions greatly appreciated.
Thanks
Bruce.
This discussion has been closed.
Comments
Rather than using the DetailBand.BeforeGenerate event, you are going to want
to use the OnCalc event of a TppVariable to make any calculations. This is
the only event that is guaranteed to fire only once per traversal (if set to
do so).
http://www.digital-metaphors.com/rbWiki/Delphi_Code/Calculations/Overview
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I've added a variable in the detail band and used it's OnCalc to the
calculations.
This does not seem to have fixed the problem.
That is: the first line on a new page has double the actual totals. Not the
first page, just the first line on new pages after page 1.
Clearly I am missing something here!
Bruce.
I thought the BeforeGenerate event was guaranteed to fire only once when the
record was to be printed? Which scenario would cause the BeforeGenerate
event to fire multiple times for a single record?
We use the BeforeGenerate event because it only gets called if the Band is
visible and that allows us to control whether amounts get added to the total
by setting the visibility fo the Band on the BeforePrint.
If the BeforeGenerate does indeed have the possibility to fire multiple
times for a single record then (a) we've been lucky over the years that it
seems to never have and (b) we need to start updating all our reports to use
a Variable as you suggested.
Would it be possible that this never happened to us because we make sure a
Band never prints on multiple pages (KeepTogether) and becaues most of our
reports are single line per record?
Scott
How are you hiding the detail band? Are you able to trace into the OnCalc
event and see where the values are coming from? If you are displaying the
totals in the group footer, you should only need to place the TppVariable(s)
in that band.
If you would like you can send me a simple example I can run on my machine
that demonstrates this issue and I'll take a look at it for you. Send the
example to support@digital-metaphors.com in .zip format.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
The OnCalc event of a TppVariable is the only event guaranteed to fire once
per traversal. Though in most cases, the BeforeGenerate event does fire
only once per band, there is no logic in place to ensure that. In some
special cases, it may be necessary to make calculations in the
BeforeGenerate however it is not recommended.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I hide the detail band by setting it's height to zero and the three fields
to not visible.
What I have is one Variable in the detail band and I'm using it's OnCalc to
add the value of the only database field in the detail band, this is the
receipt line total, to the appropriate group footer Variable.
If you watch what happens when the OnCalc fires, it processes the first line
on page two, then shows page 1.
When you click to the next page it processes the first line on page two
again, and so the footer totals accumulate two sets of the values in line 1
Page two.
I'm not sure how I can send you this, it's part of a big app with lots of
DBISAM data tables.
Thanks and regards,
Bruce.
As I mentioned before, there should be no need to place the TppVariable in
the detail band. Placing it inside the GroupFooter with its Timing set to
calculate on Traversal will fire the OnCalc event for each record change.
What I really need is a simple example (perhaps using the DBDEMOS database)
that is similar to the report you are trying to create that I can easily run
on my machine.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Don't know if you've resolved this - I have a similar problem when
upgrading a report written in RB6 to RB11.
After a day of tearing out hair - I noticed that the variable that
contained the calculations was set to type 'String' - changing this to
type 'Interger' (only using integers in this case) fixed the problem.
Regards
Rod North
For versions of ReportBuilder 9 or later it is necessary to set a variable
to a numeric type if making numeric calculations. This was to fix string
building cases with the the TppVariable component.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com