I have a form with a subform in datasheet view. The main form is for creating new orders and the subform records the items for each order.
In the after update event of the "Part" field on the subform, the part price is looked up with a Dlookup and placed in the appropriate field on the subform.
What I am trying to do is have a running "Price Total" field on the MAIN form which sums all the part prices on the subform. Using the Dsum I can accurately sum all the part prices from the subform which match the order number on the main form.
The problem is that I cannot get the "Price Total" field to automatically update itself, even when it is supposedly changed in the afterupdate event of the subform field. It updates only after a part is selected and the selected again. ( i want it to update the price total after only one selection of the part on the subform)
Here is the afterupdate event for the part field on the subform:
total = DSum("[PartPrice]", "SubForm_Source", "OrderNbr = " & Forms![MainForm]![OrderNbr])
Forms![MainForm]![PriceTotal] = total
"total" is declared as a public variable of type Double in a module.
I have also tried the afterinsert event of the subform and making the control source of the "PriceTotal" field a dsum function. Neither of these things corrected the problem. Two selections of the part were still required before the PriceTotal would update itself.
Thanks for the idea, but that didn't seem to do anything.
I placed the line
right above the total line.
In theory I completely agree with what you said, but it seemed to have no effect at all on the form.
I don't know if it makes any difference or not, but I failed to mention in my previous post that "Part" on the subform is a combo box and the user is selecting this with the mouse. I also noticed that I get "PriceTotal" to update not only when I select that same part and then select it again, but also when I have multiple records on the subform and I go back and change a part which is not the final record.