How to automaticaly sum

Hi all.

I have a form to create “shipment guides”: it is a card form with a subform container to display the document lines.

What I need is a way to automaticaly sum, based on some pre-defined conditions__***__, the quantity that user inputs to a line of the tabular-type form. That is: each shipment guide as several pre-defined lines in which the user only inserts the quantity of each item to ship; there will be a line marked as “Totalizer” were the above lines will be sumed for.

So, each time the user inputs a quantity that value will be automaticaly add to the totalizer field.

***I have created a “shipment guide template” in which are defined the line items and those lines that will be the sum of the above ones.

Thank you all in advance,


You could use the CALCSUMS method. Or just keep a running total in your own variable.

if you can identify totalizer line in which you want to update sum up all the lines quantity you could do it by write code in Qty to ship field onvalidate trigger.

Thank you all.

I solved the problem by placing code in the OnValidate trigger.

First off all, in the “shipment guide template” I defined these fields “Agrupamento Totais” and the “Totalizador”. The first one (an int data type), is used to identify the items that will be added to the totalizer, and the second one (a boolean data type), is the sum field (which also has to be in the same range of “Agupamento Totais”).

Then, in the “shipment guide form”:

Quantidade - OnValidate()
IF “Agrupamento Totais” = 1 THEN BEGIN
gTotal1 := 0;
gTotal1 := Quantidade - xRec.Quantidade;
g_LinGuiaTransp.SETRANGE(g_LinGuiaTransp.“Nº Documento”,“Nº Documento”);
g_LinGuiaTransp.SETRANGE(“Agrupamento Totais”,1);
IF g_LinGuiaTransp.FIND(’-’) THEN REPEAT
IF (NOT g_LinGuiaTransp.“Factura Unidade”) AND (NOT g_LinGuiaTransp.“Factura Peso”)
AND (NOT g_LinGuiaTransp.“Totalizador?”) THEN
gTotal1 += g_LinGuiaTransp.Quantidade;

IF (g_LinGuiaTransp.“Totalizador?”) AND (g_LinGuiaTransp.“Agrupamento Totais” = 1) THEN BEGIN
g_LinGuiaTransp.Quantidade := gTotal1;
UNTIL g_LinGuiaTransp.NEXT=0;

END IF “Agrupamento Totais” = 2 THEN BEGIN …

Quantidade - OnAfterValidate()