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

This article was previously published under Q119134
This article has been archived. It is offered "as is" and will no longer be updated.
Moderate: Requires basic macro, coding, and interoperability skills.
SUMMARY
This article demonstrates how to correctly reference a subtotal control ona subform from a main form.

NOTE: This article explains a technique demonstrated in the samplefiles, FrmSampl.exe (for Microsoft Access for Windows 95 version 7.0)and FrmSmp97.exe (for Microsoft Access 97). For information about howto obtain these sample files, please see the following articles in theMicrosoft Knowledge Base:

150895 ACC95: Microsoft Access Sample Forms Available in Download Center

175066 ACC97: Microsoft Access 97 Sample Forms Available in Download Center
MORE INFORMATION
If you try to sum a subform field using a calculated control on a mainform, you may receive an error message in the main form control. Forexample, 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 using a calculatedcontrol in the subform's form footer. You can then reference thecalculated control from the main form to display the summed value.

This technique is demonstrated in the Orders form of the sample databaseNorthwind.mdb in Microsoft Access 7.0 and 97 and NWIND.MDB in MicrosoftAccess 1.x and 2.0. The Orders Subform contains a calculated control inthe subform's form footer. This calculated control sums the subform'sExtended Price field to create a subtotal using the following syntax:

In Microsoft Access 7.0 and 97:
   Text Box Control      Name: OrderSubtotal      ControlSource: =Sum([ExtendedPrice])				

In Microsoft Access 1.x and 2.0:
   Text Box Control      Name: Order Subtotal      ControlSource: =Sum([Extended Price])				

Because the subform's DefaultView property is set to Datasheet, you do notsee the calculated control in the subform's form footer when you open theOrders form in Form view. However, a text box control on the main formrefers to the subform's calculated control and displays its value. Themain form control is called Subtotal and references the subform'scalculated control using the following syntax:

In Microsoft Access 7.0 and 97:
   Text Box Control      Name: Subtotal      ControlSource: =[OrdersSubform].[Form]![OrderSubtotal]				

In Microsoft Access 1.x and 2.0:
   Text Box Control      Name: Subtotal      ControlSource: =[Orders Subform].[Form]![Order Subtotal]				

This reference allows the main form to display a subtotal of a subformfield while the actual totaling of subform values is performed using acalculated control in the subform's form footer.
REFERENCES
For more information about referencing subform controls, search for"subforms," then "referring to in expressions," and then "Calculate atotal in a subform and display it on a form" using the Microsoft AccessHelp Index.
totals
Properties

Article ID: 119134 - Last Review: 12/04/2015 10:24:14 - Revision: 2.1

Microsoft Access 1.0 Standard Edition, Microsoft Access 1.1 Standard Edition, Microsoft Access 2.0 Standard Edition, Microsoft Access 95 Standard Edition, Microsoft Access 97 Standard Edition

  • kbnosurvey kbarchive kbhowto kbusage KB119134
Feedback