% of total calculation

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.
 
D

Dirk Goldgar

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top