% of total calculation

  • Thread starter Thread starter Allan May
  • Start date Start date
A

Allan May

I have a form that calculates a field as a % total.
Basically, each line has a quantity and I need to know
what % of the total that quantity is. I am using
[quantity]/sum[quantity]*100.

However, when I modify the quantity, the % doesn't change
to the correct % until I move to the next record. Is
there a way to make it do the sum calculation without
requiring the move to the next record?

Thanks.
 
Allan May said:
I have a form that calculates a field as a % total.
Basically, each line has a quantity and I need to know
what % of the total that quantity is. I am using
[quantity]/sum[quantity]*100.

However, when I modify the quantity, the % doesn't change
to the correct % until I move to the next record. Is
there a way to make it do the sum calculation without
requiring the move to the next record?

Thanks.

You have to force the record to be saved, which you can do with code in
the control's AfterUpdate event like this:

Private Sub Quantity_AfterUpdate()
RunCommand acCmdSaveRecord
End Sub

However, if the record can't be saved for some reason -- missing a
required field, for example -- the attempt to save it will raise an
error.

There is a way to make the calculation come out right for the current
record only, even without saving the record, but that will leave the
calculated field incorrect on the other records, which will be
noticeable on a continuous form.
 
Back
Top