Microsoft Access Functions
Microsoft Access Functions
Notes
• When you set the Name property of a calculated control, make sure you use a
unique name. Don't use the name of one of the controls you used in the
expression.
• You can't use the name of a control in an expression that uses an aggregate
function; you must use only field names from a table, query, or SQL
statement. For information about using aggregate functions with calculated
controls, click .
Notes
• When you set the Name property of a calculated control, make sure you use a
unique name. Don't use the name of one of the controls you used in the
expression.
• You can't use the name of a control in an expression that uses a domain
aggregate function; you must use only field names from a table, query, or SQL
statement. For information about using domain aggregate functions with
Notes
• When you set the Name property of a calculated control in a form or report, or
set the ID property of a calculated control in a data access page, make sure
that you use a unique name. Don't use the name or ID of one of the controls
you used in the expression.
• In an expression on a form or report, you can use the name of a control or the
name of a field in the underlying record source. In an expression on a data
access page, you can use only the name of a field that's in the data definition
of the page.
Notes
• When you set the Name property of a calculated control in a form or report, or
set the ID property of a calculated control in a data access page, make sure to
use a unique name. Don't use the name or ID of one of the controls that you
used in the expression.
• In an expression on a form or report, you can use the name of a control or the
name of a field in the underlying record source. In an expression on a data
access page, you can use only the name of a field that's in the data definition
of the page.
• 1.1 is the value by which Microsoft Access multiplies the value of the Freight
control.
Examples of referring to
values on forms and reports
The following table lists examples of expressions you can use in
calculated controls on forms.
If you use this expression Microsoft Access displays
=Forms![Orders]![OrderID] The value of the OrderID control on the
Orders form.
=Forms![Orders]![Orders Subform]! The value of the OrderSubtotal control on
[OrderSubtotal] the Orders Subform on the Orders form.
=Forms![Orders]![Orders Subform]! The value of the third column in ProductID,
[ProductID].Column(2) a multiple-column list box on the Orders
Subform on the Orders form. (0 refers to the
first column, 1 refers to the second, and so
on.)
=Forms![Orders]![Orders Subform]! The product of the value of the Price control
[Price]*1.06 on the Orders Subform on the Orders form
and 1.06 (adds 6 percent to the value of the
Price control).
=Parent![OrderID] The value of the OrderID control on the
main or parent form of the current subform.
Notes
• When you set the Name property of a calculated control, make sure you use a
unique name. Don't use the name of one of the controls you used in the
expression.
Examples of performing
arithmetic operations in
forms, reports, and data
access pages
The following table lists examples of expressions that you can use in
calculated controls on forms, reports, and data access pages.
If you use this expression Microsoft Access displays
=[Subtotal]+[Freight] The sum of the values of the Subtotal and
Freight fields.
=[RequiredDate]-[ShippedDate] The difference between the values of the
RequiredDate and ShippedDate fields.
=[Price]*1.06 The product of the value of the Price field
and 1.06 (adds 6 percent to the Price value).
=[Quantity]*[Price] The product of the values of the Quantity
and Price fields.
=[EmployeeTotal]/[CountryTotal] The quotient of the values of the
EmployeeTotal and CountryTotal fields.
Notes
• In the ControlSource property of a calculated control, precede the expression
with the = operator. On a data access page, you can omit the = operator, and
type an alias instead; for example, type ExtendedPrice: [Quantity]*[Price].
• When you set the Name property of a calculated control in a form or report, or
set the ID property of a calculated control on a data access page, make sure to
use a unique name. Don't use the name or ID of one of the controls that you
used in the expression.
• In an expression on a form or report, you can use the name of a control or the
name of a field in the underlying record source. In an expression on a data
access page, you can use only the name of a field that's in the data definition
of the page.
• When you use an arithmetic operator (+, -, *, /) in an expression, and the value
of one of the controls in the expression is Null, the result of the entire
expression will be Null. On a form or report, if some records in one of the
controls that you used in the expression might have a Null value, you can
convert the Null value to zero by using the Nz function; for example:
=Nz([Subtotal])+Nz([Freight])
Notes
• When you set the Name property of a calculated control in a form or report, or
set the ID property of a calculated control in a data access page, make sure to
use a unique name. Don't use the name or ID of one of the controls that you
used in the expression.
• In an expression on a form or report, you can use the name of a control or field
in the underlying record source. In an expression on a data access page, you
can use only the name of a field that's in the data definition of that page.
Examples of expressions that
calculate on or manipulate
values by using a calculated
field in a query
Enter the expression for the calculated field in the Field cell in the
query design grid.
FullName: [FirstName] & " " & Displays the value of the FirstName and
[LastName] LastName fields, separated by a space, in
the FullName field.
Address2: [City] & " " & [Region] & " " Displays the value of the City, Region, and
& [PostalCode] PostalCode fields, separated by spaces, in
the Address2 field.
ProductInitial: Left([ProductName], 1) Uses the Left function to display in the
ProductInitial field the first character of the
value in the ProductName field.
TypeCode: Right([AssetCode], 2) Uses the Right function to display in the
TypeCode field the last two characters of
the value in the AssetCode field.
AreaCode: Mid([Phone],2,3) Uses the Mid function to display in the
AreaCode field the three characters starting
with the second character of the value in the
Phone field.
You can also use a calculation to update data from an update query.
For example, you can enter the following expression in the Update
To cell to increase all the values in the UnitPrice field by 5 percent.
Example of a subquery in a
calculated field
You enter the expression in the Field cell in the query design grid.
The fields you reference in the expression are from the tables or
queries in the current query.
Expression Description
Cat: (SELECT [CategoryName] FROM [Categories] Displays the CategoryName if
WHERE [Products].[CategoryID]=[Categories]. the CategoryID from the
[CategoryID]) Categories table is the same as
the CategoryID from the
Products table.
.
Examples of expressions in
update queries
Use expressions such as the following in the Update To cell in the
query design grid for the field you want to update.
Expression Result
"Salesperson" Changes value to Salesperson
#8/10/96# Changes date values to 10-Aug-96
Yes Changes No values in a Yes/No field to Yes
"PN"&[PartNumber] Adds PN to the beginning of each specified
part number
[UnitPrice]*[Quantity] Calculates the product of UnitPrice and
Quantity
[Freight]*1.5 Increases freight charges by 50 percent
DSum("[Quantity]*[UnitPrice]", Where the Product IDs in the current table
"Order Details","[ProductID]=" & match the Product IDs in the Order Details
[ProductID]) table, updates sales totals based on the
product of Quantity and UnitPrice
Right([ShipPostalCode],5) Truncates the leftmost characters in a field,
leaving the five rightmost characters
Quantity 1 1
Region "MT" MT
Region "New York, N.Y." New York, N.Y (note that you must
enclose the value in quotes if it
includes punctuation)
Fax "" A zero-length string to indicate that
by default this field should be empty
Order Date Date( ) Today's date