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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating Totals from Subform 1

Status
Not open for further replies.

cityboy3

Programmer
Nov 6, 2002
41
US
I have a Main form (an invoice) with a subform containing line items. The footer of the subform has a calculated text box containing a total. I want to set up a text box in my main form, bound to the record that is displayed in the main form, that copies the value from the subform footer. Should be simple enough...

In the AfterUpdate event for the subform, I have code that sets the text box in the main form to equal my subform total field. What seems to be happening is that the AfterUpdate event is somehow firing before the subform calculates its total in the footer. So the field in the main form always gets set to the previous value of the subform's total field. Interestingly, if I set a breakpoint in the code then everything works fine, i.e. the code breaks, I hit play, and the value in the main form sets correctly. I'm assuming that this is because I've given the subform enough time to synchronize itself before the code runs.

I've tried to do several things to force the subform to recalculate before setting the field in the main form. I've use the refresh and requery methods on the subform. I also tried setting the focus to the total field on the subform before running my code. Nothing works.

Any ideas?

thanks in advance
 
Hi!

Did you also try the Recalc method? It forces recalculation of calculated controls (I'd perhaps also play with the after update event of controls this controls calculations are dependent of). Syntax: Me.Recalc

Roy-Vidar
 
Looks like I spoke too quickly. Even when I use Recalc, sometimes the rest of the code executes and resets the main form fields before the recalc finishes. I find that the only way to stop this is by calling DoEvents inside a For...Next Loop.

It feels kludgy. Is there another way?
 
If that's kludgy, you'd better see some of the things I've done, eeh, well, never mind;-)

Should perhaps have seen it in the previous post. Issue a recalc in the after update event of the control bound to the field you sum, then the correct sum should be available at the time the form reaches the after update, where you push the value to the main form.

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top