Microsoft KB Archive/148302

= ACC95: Domain Aggregate Functions Return #Error When Interrupted =

Article ID: 148302

Article Last Modified on 11/17/2000

-

APPLIES TO


 * Microsoft Access 95 Standard Edition

-



This article was previously published under Q148302





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

When you use Microsoft Access domain aggregate (totals) functions on a form, the functions may return the "#Error" message. Domain aggregate functions, such as DSum and DCount, evaluate an entire column or set of data (a domain).



CAUSE
This error occurs when focus is moved from the form's active control to any other control before the domain aggregate function has finished calculating. This behavior occurs with all domain aggregate functions.



RESOLUTION
Use one of the two following methods to work around this problem.

Method 1
  Open the form containing the domain aggregate function in Design view and set the form's OnCurrent property to the following event procedure

Sub Form_Current Me! =      End Sub

where refers to the name of the text box control on the form where you want to display the result of the expression and refers to the domain aggregate function expression used to complete your calculation.  Select the text box control containing the domain aggregate function. Delete the formula currently in the ControlSource property.

Method 2
  Create the following new macro

     Macro Name       Macro Action -     DFunctionMacro   SetValue

DFunctionMacro Actions ---     SetValue Item: Expression:

where refers to the name of the text box control on the form where you want to display the result of the expression and refers to the domain aggregate function expression used to complete your calculation. </li> Select the text box control containing the domain aggregate function.</li> Delete the formula currently in the ControlSource property.</li> Set the form's OnCurrent property to the DFunctionMacro macro.</li></ol>

<div class="status_section">

STATUS
Microsoft has confirmed this to be a problem in Microsoft Access 7.0. This problem no longer occurs in Microsoft Access 97.

<div class="moreinformation_section">

Steps to Reproduce Problem
CAUTION: Following the steps in this example will modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file or perform these steps on a copy of the Northwind database.

 Open the sample database Northwind.mdb.</li> Open Orders form in Design view.</li>  Add the following unbound text box to the form:

NOTE: In the following example, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating the ControlSource property.

<pre class="fixed_text">    Text box: MyDomain -    ControlSource: (Choose one of the following Domain Aggregate     functions)

=DSUM("UnitPrice","Order Details Extended")*DSUM("ProductID","Order _        Details  Extended")

=DCOUNT("UnitPrice","Order Details Extended")*DCOUNT("ProductID", _        "Order Details Extended") </li> Switch the Orders form to Form view to ensure that the formula returns a value.</li> Switch the Orders form back to Design view.</li> Switch the Orders form back to Form view, and using the mouse, quickly place the pointer in the Salesperson combo box. This must be done while the domain aggregate function is calculating.

NOTE: In most cases #Error is returned in the text box when the calculation is interrupted and fails. Whether or not the #Error occurs depends on how quickly the focus is moved from the active control.</li></ol>

<div class="references_section">