in the footer of my report, I want the sum of fieldvalue from the detailband. But the value isn't correct. It is the value of the page plus the value of the first field on the next page.
There is a limitation of ReportBuilder when calculating sums inside the footer band with a dynamic height detail band. Although we usually do not recommend this, you can try summing a TppVariable using the DetailBand.AfterPrint event which may help.
procedure DeatilAfterPrint; begin if not blnFirstPass then begin intMenge:=intMenge+dbtMengeGesamt.FieldValue; dblSumme1:=dblSumme1+dbtSumme1.FieldValue; dblSumme2:=dblSumme2+dbtSumme2.FieldValue; lblSumme1.Caption:=FormatFloat('#,0.00;-#,0.00', dblSumme1); lblSumme2.Caption:=FormatFloat('#,0.00;-#,0.00', dblSumme2); lblMenge2.Caption:=IntToStr(intMenge); end; end;
But now, I must browse from page to page to get correct SUM on each page.
> It is the value of the page plus the value of the first field > on the next page.
... well - though I had this problem while dealing with several groups it was nearly the same: It seems like RB calls the events even when "testing" whether a band fits on the end of the page or does not. In my case more than one value was calculated double times and though I was only calculating a grand total for the whole report I had the same effect (browsing page by page resulted in correct values).
I found a workaround by adding a unique dataset-id (AutoIncrement-field) to a collection and checking if an ID was already within this collection before adding it to the sum - like:
IF not IsPrinted(myTableID.Value) THEN BEGIN Sum:=Sum+myTableTOBEADDED.Value; SaveAsAlreadyAdded(myTableID.Value); END;
This way I'm trying to prevent RB from calling this code twice. I know that this is complicated - but unfortunately that's the only thing that makes me shure that my customers won't get wrong results...
Mark is correct, most of the events in ReportBuilder are fired numerous times during generation. To work around this you will need to compare your current record being used to it's previous value when you fired this event to be sure you have infact moved on to the next record.
Comments
There is a limitation of ReportBuilder when calculating sums inside the
footer band with a dynamic height detail band. Although we usually do not
recommend this, you can try summing a TppVariable using the
DetailBand.AfterPrint event which may help.
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I have done this:
procedure DeatilAfterPrint;
begin
if not blnFirstPass then begin
intMenge:=intMenge+dbtMengeGesamt.FieldValue;
dblSumme1:=dblSumme1+dbtSumme1.FieldValue;
dblSumme2:=dblSumme2+dbtSumme2.FieldValue;
lblSumme1.Caption:=FormatFloat('#,0.00;-#,0.00', dblSumme1);
lblSumme2.Caption:=FormatFloat('#,0.00;-#,0.00', dblSumme2);
lblMenge2.Caption:=IntToStr(intMenge);
end;
end;
But now, I must browse from page to page to get correct SUM on each page.
are you using grouping functionality?
Kind regards,
Mark
the next page.
... well - though I had this problem while dealing with several groups
it was nearly the same: It seems like RB calls the events even when
"testing" whether a band fits on the end of the page or does not. In my
case more than one value was calculated double times and though I was
only calculating a grand total for the whole report I had the same
effect (browsing page by page resulted in correct values).
I found a workaround by adding a unique dataset-id
(AutoIncrement-field) to a collection and checking if an ID was already
within this collection before adding it to the sum - like:
IF not IsPrinted(myTableID.Value) THEN
BEGIN
Sum:=Sum+myTableTOBEADDED.Value;
SaveAsAlreadyAdded(myTableID.Value);
END;
This way I'm trying to prevent RB from calling this code twice. I know
that this is complicated - but unfortunately that's the only thing that
makes me shure that my customers won't get wrong results...
Kind regards,
Mark Meyer
No. In this case not.
Mark is correct, most of the events in ReportBuilder are fired numerous
times during generation. To work around this you will need to compare your
current record being used to it's previous value when you fired this event
to be sure you have infact moved on to the next record.
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com