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

Sum Calculated Control On Main Form

Status
Not open for further replies.

Mav3000

Technical User
Jun 20, 2005
113
GB
Hi All, You've probably come across this problem many times. I've read numerous articles on this, but none address my particular problem.

I have a form [frmLedger] which has a subform [frmInvoice] which in turn has a subform [frmInvoice_Items].

I have a calculated control which is in the footer of [frmInvoice_Items] which I have successfully referenced in [frmInvoice]. i.e. [frmInvoice] shows the Sum of [frmInvoice_Items].[Invoice_Item_Value].

However, I need to show the Total Invoice Value on [frmLedger]. i.e. the Sum Total of the Sum Total.

I have tried to do this using DSum but I can't get the formula to work - it just comes up with 'Error'.

My Tables are as follows:

[tblLedger]
[Ledger_ID]

[tblInvoice]
[Invoice_ID]
[Ledger_ID]

[tblInvoice_Items]
[Invoice_Item_ID]
[Invoice_ID]
[Invoice_Item_Value]

My DSum formula in the [frmLedger] txtTotal_Invoice control looks like this:

=Dsum("[Invoice_Item_Value],"tblInvoice_Items","[tblInvoice_Items]![Invoice_ID]=[tblInvoice]![Invoice_ID] AND [tblInvoice]![Ledger_ID]=[tblLedger]![Ledger_ID]

Am I doing this correctly? or is there a way of doing this through a form? I have read on Office Online about referencing the calculated control in an SQL query, but this makes no sense to me.

Any help would be appreciated,

Richard
 
I doubt any of those solutions will work correctly. It isn't clear to me whether the text box in frmLedger should display results from one invoice or all invoices from the ledger.

Regardless, I would probably create a query from the tables that groups by invoiceid and totals the Invoice_Item_Value field. Then use this query as the domain in the DSum() function.

The equal sign must be inside the quotes, not outside. You can only use fields inside the quotes that are in the domain.

Duane
Hook'D on Access
MS Access MVP
 
Excellent - thank you very much for the reply. I now have the total working nicely. It doesn't automatically update however when the total on the sub-form changes.

Do I need to add some sort of 'after update' code into the sub-form to update the dsum field on the main form?

I'd like it to update while the record in the sub form is still open (although to keep the update until the record is saved is fine).

Thanks, Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top