Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Bring a Subtotal from a Subform to a Main Form


View products that this article applies to.

Summary

This article shows you how to reference a subtotal control on a subform from a main form.

↑ Back to the top


More information

If you try to sum a subform field by using a calculated control on a main form, you may receive an error message in the main form control. For example, the following expression in a main form control generates a "#Name?" error message:
   =Sum([MySubForm].Form![ExtendedPrice])
				
To avoid an error, you can sum the subform field by using a calculated control in the subform's form footer. You can then reference the calculated control from the main form to display the summed value.

There's an example of this method in the Orders form of the Northwind sample database. First, a calculated control in the footer of the Orders Subform sums the subform's Extended Price field to create a subtotal. It uses the following syntax:
   Text Box Control
   ----------------
   Name: OrderSubtotal
   ControlSource: =Sum([ExtendedPrice])
				
Because the subform's DefaultView property is set to Datasheet, you do not see the calculated control in the subform's form footer when you open the Orders form in Form view. However, a text box control on the main Orders form refers to the subform's calculated control and gets its value to display. The main form control is called Subtotal and references the subform's calculated control. It uses the following syntax:
   Text Box Control
   ----------------
   Name: Subtotal
   ControlSource: =[Orders Subform].[Form]![OrderSubtotal]
				
This reference allows the main form to display a subtotal of a subform control while the actual totaling of subform values is performed by using a calculated control in the subform's form footer.

↑ Back to the top


References

For more information about referencing subform controls, click Microsoft Access Help on the Help menu, type calculating a total in a subform in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB208998, kbusage, kbhowto

↑ Back to the top

Article Info
Article ID : 208998
Revision : 2
Created on : 6/24/2004
Published on : 6/24/2004
Exists online : False
Views : 246