I have a form with two subforms. I need to sum amounts in both forms,
calculate the difference, and then store this amount in the table accessed by
the main form. How can I best make this happen?
Put a textbox on the Footer of each subform with a Control Source
=Sum([fieldname])
Let's say you have SubformA and SubformB, with txtTotal on each. On
the mainform put a control
=SubformA.Form!txtTotal - SubformB.Form!txtTotal
This will display the difference.
It's probably a VERY BAD IDEA to store that difference in a table.
What if one of the records on one of the related tables gets deleted
or edited? Your stored sum is now WRONG, with no easy way to detect
that fact. It's possible to use some VBA code to store the value, but
it will be difficult since you'll need some way to be sure that all
records have been added (and edited) in the subforms before you try to
store it. I'd really suggest just recalculating it (as described, or
with a Totals query) as needed, and NOT storing it.
John W. Vinson[MVP]