As you worked through the lesson on calculations, you may have thought that the calculation you really wanted to create was a sum of hours worked on one project for the Projects form. Unfortunately, displaying aggregate calculations on a form is rather complicated. However you may find that the ease of creating aggregate calculations on reports with the Report Wizard makes up for that.
You might want to try working around the aggregate calculation problem by
creating a query that includes all the data you need on your form as well as a new field that calculates the result you want to display on the form.
Aggregates, Unique Values, and Top Values:
Unlike Access 2010 web databases, web apps do support aggregate queries, with the familiar aggregate functions you have in client queries.
Not only are they much faster to build and view than equivalent data macros, but you can also use them as sources for data macros. As you may expect, you still can specify whether a query should return only distinct values or restrict the numbers of rows returned.
Table 4-14 Rules for Updating Queries
Type of Query or Field
Updateable
Comments
Many-to-one-to-many relationship
No
Can update data in a form or data access page if Record Type = Recordset
Two or more tables with no join line
No
Must have a join to determine updateability
Crosstab
No
Creates a snapshot of the data
Totals query (Sum, Avg, and so on)
No
Works with grouped data creating a snapshot
Unique Value property is Yes
No
Shows unique records only in a snapshot
SQL-specific queries
No
Union and pass-through work with ODBC data
Calculated fields
No
Will recalculate automatically
Read-only fields
No
If opened read-only or on read-only drive (CD-ROM)
Permissions denied
No
Insert, replace, or delete not granted in older MDB databases that use user-level security
ODBC tables with no unique identifier
No
Unique identifier must exist
Paradox table with no primary key
No
Primary key file must exist
Locked by another user
No
Can’t be updated while a field is locked by another
Overcoming Query Limitations
Table 4-14 shows that there are times when queries and fi elds in tables are not updateable.
As a general rule, any query that performs aggregate operations or uses an ODBC data source is not updateable; most other queries can be updated.
When your query has more than one table and some of the tables have a one-to-many relationship, some fields might not be updateable (depending on the design of the query).
Updating unique index (primary key):
If a query uses two tables involved in a one-to-many relationship, the query must include
the primary key from the one table. Access must have the primary key value so that they
can find the related records in the two tables.
Create a Calculated Control on Report:
You can create a calculated control on a report, but in general the place to create calculations is in a query or in a report form. The result of a calculation in a query can easily be displayed in a form if the query is used as the basis for the form. To create a calculated control, you need to do two things:
Create the new control.
Type in the expression for the calculation.
The following series of images takes you through the process.
Add Calculated Control in Access
You can use calculated controls in Access databases to display the results of a calculation. For example, if you have a report that displays the number of items sold and the price of each unit, you can add a calculated text box that multiplies those two
fields to display the total price. The Control Source property of the calculated text box contains an expression that multiplies two fields (the number of items times the unit price) to obtain the result.
This procedure helps you create a calculated control without using a control wizard.
Right-click the form or report in the Navigation Pane, and then click Design View Button image.
On the Design tab, in the Controls group, click the tool for the type of control you want to create.
For a list of control types that can be used as calculated controls, see the section Learn which types of controls can be used as calculated controls.
Position the pointer where you want the control to be placed on the form or report, and then click on the form or report to insert the control.
If a control wizard starts, click Cancel to close it.
Select the control, press F4 to display the property sheet, and then type an expression in the Control Source property box. To use the Expression Builder to create the expression, click Builder button next to the Control Source property box.
Switch to Form view or Report view and verify that the calculated control works as you expect.
The module wrap-up will review terms and concepts used in this module.