value of sum in control only exists in debug mode

G

Guest

I have a form "Procedures" with a subform "ProcedureItems Subform". I need
to pass the sum of the values in the subform to the parent form's table, i.e.
a bound control. The sum is stored in a control (txtTotalCost) in the footer
(control source=sum([Total Cost])).

I tried using the subform exit event, but doing so disables the form navi
buttons while in the subform.

I'm now trying to use the afterchange event in the subform, but the bound
control gets set to zero, unless I'm in debug mode. It seems txtTotalCost
doesn't have a value when the code is running outside of debug mode.

How can I pass this value successfully to my bound control?
(Yes, I know I shouldn't be setting the total cost, and this leads to data
inconsistencies. However, I need the total cost in the subform of a subform
of another form and using aggregate functions doesn't allow editability in
that subform.)
 
W

Wayne Morgan

I believe you're running into timing problems. The calculation in the
textbox probably hasn't been completed at the time you try to get the value
from it. The best way around this is to redo the calculation in your code.
You should be able to use a DSum() function, passing the same parameters
that are limiting the records displayed in the subform (i.e. the value of
the Child Link field and any other filters you may have applied or are
applied in the subform's query) for the WHERE argument in the DSum()
function.
 

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