ACC: Cannot Sum Calculated Controls in Forms or Reports

Last reviewed: May 7, 1997
Article ID: Q113354
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0, 97

SYMPTOMS

Moderate: Requires basic macro, coding, and interoperability skills.

When you open a form or report, "#Name?" is displayed in a text box in a form footer, or a parameter box appears requesting the field specified in the sum expression in a report.

CAUSE

The text box is trying to perform a sum on a calculated control in the form or report and because Microsoft Access does not store calculated values, it cannot sum the calculated field.

RESOLUTION

There are two workarounds to this behavior:

  1. Repeat the calculation being computed in the calculated control in the sum expression. If the calculated control on the form or report has the expression

          =[UnitPrice] * [Quantity]
    

    repeat this calculation in the sum expression as:

          =SUM([UnitPrice] * [Quantity])
    

    NOTE: In versions 1.x and 2.0, there is a space in Unit Price.

  2. Base the form or report on a query and calculate the expression as a calculated field in the query, rather than as a calculated control on the form or report. Because the calculation is being computed in the query, the result will be available for other computations. This method is considerably faster than the first method because the computation does not have to be repeated. If the calculated control on the form or report has the expression

          =[UnitPrice] * [Quantity]
    

    then the new calculated field in the query will have the following in the Field row of the query grid:

          ExtendedPrice: [UnitPrice] * [Quantity]
    

    If the form or report is based on a query with this calculated field, ExtendedPrice will appear in the field list and should be used in place of the calculated control on the form or report. The sum expression in the form or report footer would look like the following:

          =SUM([ExtendedPrice])
    

MORE INFORMATION

Steps to Reproduce Behavior

  1. Open the sample database Northwind.MDB (or NWIND.MDB in versions 1.x and 2.0).

  2. Open the Orders Subform form in Design view.

  3. Add a text box with the following properties to the detail section:

          Name: My Extended Price
          ControlSource: =[UnitPrice] * [Quantity]
    

  4. Change the Order Subtotal text box ControlSource property from

          =Sum([ExtendedPrice])
    

    to:

          =Sum([My Extended Price])
    

    NOTE: The original expression will correctly display the sum of the ExtendedPrice field because this field is being computed as a calculated field in the Order Details Extended query the form is based on. The ExtendedPrice calculated field in the Order Details Extended query looks like the following:

          ExtendedPrice: CCur([Order Details].[UnitPrice]*[Quantity]*(1-
          [Discount])*100)/100
    

  5. Change the form's Default View property from Datasheet to Single Form.

  6. View the form in Form view. Note that "#Name?" appears in the Order Subtotal box in the form footer.

Work Around 1: Repeating the Calculation in the Sum Expression

NOTE: These steps continue from the "Steps to Reproduce Behavior" section above.

Change the Order Subtotal ControlSource property from

   =Sum([My Extended Price])

to:

   =Sum([UnitPrice] * [Quantity])

Note that the calculation is correctly displayed in the Order Subtotal box in the form footer.

Work Around 2: Repeating the Calculation in the Sum Expression

  1. Open the Order Details Extended query in Design view.

  2. In an empty query grid column, type the following line in the Field row:

          My Extended Price: [Order Details].[UnitPrice]*[Quantity]
    

  3. Remove the My Extended Price calculated control in the detail section. Note that the calculation is correctly displayed in the Order Subtotal box in the form footer.

REFERENCES

For more information about using calculated controls in forms and reports, search the Help Index for "Calculated Controls," or ask the Microsoft Access 97 Office Assistant.


Keywords : FmsSubf kberrmsg kbusage
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Hardware : X86
Issue type : kbprb
Resolution Type : Info_Provided


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 7, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.