I’m not used to create reports, so this will be a stupid question. I’m unable to create a total in a report based on item ledger entries: for each item I multiply the quantity by the cost; in the footer I want to create the total for all items… For some reason the result remains always zero. I’m using “create.total” on the predataitem trigger; adding the result after each item ledger line by “total = total + quantity * cost”; and created a new text box which is referring to “total”. What’s wrong? Thanks!
use CREATETOTALS Use this function to maintain totals for a variable in the same way as totals are maintained for fields by using the TotalFields property. CREATETOTALS(Var1 [, Var2] ,…) Var1, Var2, … Data type: decimal Comments Just like the TotalFields property, CREATETOTALS causes group and grand totals to be maintained. The totals can be printed by placing controls that have the variable or variables that are the arguments of CREATETOTALS as their source expressions in the appropriate sections: the group totals are printed in GroupFooter sections, and the grand totals are printed in Footer sections. Examples To have the system maintain totals for the two variables Amount and Quantity, use CREATETOTALS like this: CurrReport.CREATETOTALS(Amount, Quantity); -------- Another Example on how to use it. OnPreDataItem() CurrReport.CREATETOTALS(ItemTotal); OnAfterGetRecord() ItemTotal := Item.“Cost” * Item.“Qty”;
In your case it’ll look somthing like this:
OnPreDataItem() CurrReport.CREATETOTALS(Total); OnAfterGetRecord() Total := Quantity * Cost; CREATETOTALS will do the totalling for you, i.e. there’s no need for the total := total + quantity * cost
Ok, solved thanks!