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: Cannot Calculate an Expression Inside an Aggregate Function on a Form or Report in an Access Project


View products that this article applies to.

This article was previously published under Q225992
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies only to a Microsoft Access project (.adp).

↑ Back to the top


Symptoms

In a Microsoft Access project, if you place a calculation inside an aggregate (totals) function, you may see one of the following problems:
When you open a form, #Error is displayed in a text box.
-or-
You may see the following error when you try to preview or print a report:
The expression 'The expression 'expression' is invalid. @Aggregate functions are only allowed on output fields of the Record Source. @1@.

1' is invalid.

Aggregate functions are only allowed on output fields of the Record Source.

↑ Back to the top


Cause

This problem may occur when you set the ControlSource property of a text box on a form or a report to a calculated value inside an aggregate function. For example:
=Sum([Quantity]*[UnitPrice])

↑ Back to the top


Resolution

Create a field in the record source of the form or the report based on the expression, and then use the aggregate function on that field in the form or the report. For example, create a new field named TotalPrice in the Order Details Extended view. The expression to calculate TotalPrice is:
[Order Details].[Quantity]*[Order Details].[UnitPrice]
Then add a text box to the form's footer, and set the ControlSource property to =Sum([TotalPrice]).

↑ Back to the top


More information

Aggregate functions include Avg, Count, Max, Min, and Sum.

Steps to Reproduce Behavior

1.Open the sample Access project NorthwindCS.adp.
2.Open the Orders Subform in Design view.
3.In the form footer section, add an unbound text box, and set its ControlSource property to =Sum([Quantity]*[UnitPrice]).
4.Set the DefaultView property of the form to Single Form.
5.View the form in Form view.
6.Close the form without saving the changes.
7.Select the Order Details Extended view, and then on the Insert menu, click AutoReport.
8.Switch to Design view.
9.In the report footer section, add an unbound text box, and set its ControlSource property to =Sum([Quantity]*[UnitPrice]).
10.On the File menu, click Print Preview.

↑ Back to the top


Keywords: KB225992, kbclientserver, kbprb

↑ Back to the top

Article Info
Article ID : 225992
Revision : 2
Created on : 6/28/2004
Published on : 6/28/2004
Exists online : False
Views : 334