calculate the total sum into a form

calculate the total sum into a form

Hi,

I have two forms. Form A with two fields: Group and Quantity. Form B with 3 fields: Group number (a lookup type field), quantity and Sum.

I fetch into the Form B the records from the Form A that are belonging to a specific group number that I select by the lookup. I want to calculate into the Form B the sum for the column quantity, for all the fetched records. The sum calculated in the view mode of the Form B works very good, but I dont know how to have it into my Form B. So I tried to compute the sum. For that I used the script:

input.Sum = 0;
for each rind in Form_A [Group == input.Group_number]
{
input.quantity = rind.Quantity;
input.Sum = (input.Sum + input.quantity);
alert("New loop");
}

I inserted an alert to view the changes during each iteration.

Unfortunately the resulted sum is not the correct one. Any suggestion?

Doru