ACC: Storing Calculated Values Using ControlSource PropertyLast reviewed: February 4, 1998Article ID: Q109704 |
The information in this article applies to:
SUMMARYModerate: Requires basic macro, coding, and interoperability skills. This article describes the ControlSource property as it applies to controls and demonstrates how to use the SetValue macro action to store calculated values in a control's underlying table.
MORE INFORMATIONA control can be classified as bound, unbound, or calculated depending on the contents of its ControlSource property. A bound control on a form or report is linked to a field in an underlying table or query. This type of control is used to display, enter, and update data in a field. For example, the following control is a bound control:
Name: Last Name ControlSource: LastName NOTE: In Microsoft Access version 1.x, the Name property is called the ControlName property.This control displays the data from the LastName field, and stores any changes made in the control to the LastName field in the form's underlying table. A calculated control displays a value derived from data in one or more fields from the underlying table or query or from other controls. The calculation is the result of an expression assigned to the ControlSource property for that control. A calculated control can display data that is the result of an expression but cannot save data. For example, the following control is a calculated control:
Name: MyControl ControlSource: =[LastName] & ", " & [FirstName]The MyControl control displays a full name derived from an expression concatenating the last name and first name. The full name is not stored in any table. Calculated controls are often used to display calculations on a form that do not need to be stored in the underlying table. An unbound control has a ControlSource property that is blank, meaning that it is not connected to either a field from the underlying table, a query, or an expression. An unbound control can display data, but cannot save data. The data contained in an unbound control is temporary and is lost when the form or report is closed.
Storing Calculations in a FieldThe following example demonstrates how to use the SetValue macro action to store calculated values in a control's underlying table. CAUTION: Following the steps in this example will modify the sample database Northwind.mdb (or NWIND.MDB in Microsoft Access 2.0 or earlier). You may want to back up the Northwind.mdb file and perform these steps on a copy of the database.
REFERENCESFor more information about the ControlSource property, type "controlsource" in the Office Assistant, click Search, and then click to view "ControlSource Property." For more information about binding controls to fields, type "binding controls" in the Office Assistant, click Search, and then click to view "Bind an unbound control to a field." For more information about creating calculated controls, type "calculated controls" in the Office Assistant, click Search, and then click to view "Create a calculated control." Keywords : FmsHowto kbusage kbfaq Version : 1.0 1.1 2.0 7.0 97 Platform : WINDOWS Hardware : x86 Issue type : kbinfo |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |