Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating totals in subform

Status
Not open for further replies.

VaughnIT

Technical User
Jun 21, 2004
6
US
I have a form that contains a subform. In the subform I would like to calculate the field Subtotal and Total.
The subform contains:
NumPatients, LabelsPerPatient, Samples
Therefore
Subtotal = NumPatients * LabelsPerPatient
and
Total = SubTotal + Samples

How do I get these fields to be calculated?. NumPatients, LabelsPerPatient, Samples, Total and Subtotal are Number fields in my DetailTable which is the record source for the subform.

 
NumPatients, LabelsPerPatient, Samples, Total and Subtotal are Number fields in my DetailTable
You are storing calculated and derived values in your table ?
Take a look here:
Anyway, in the AfterUpdate event procedure of the NumPatients and LabelsPerPatient controls, put this code:
Me!Subtotal = Me!NumPatients * Me!LabelsPerPatient
Me!Total = Me!SubTotal + Me!Samples

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV is absolutely correct in that in many situations, it is better to calculate your calculations when you need them and not store them in a field.

(Exceptions would be where it makes sense when you want to simplify your queries, the data in the child records / subform will not change, and perhaps later you want to delete the transactions but still retain the balances)

If PNV's solution was not what you are looking for, try using...[bb]
DSum
DCount
DLookup[/bb]
...functions

These "babies" really simplify these type of calcuations.

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top