Professional Documents
Culture Documents
Ekternal Prosedur Aacces
Ekternal Prosedur Aacces
The tables in this section provide examples of expressions that calculate a value in
a control located on a form or report. To create a calculated control, you enter an
expression in the ControlSource property of the control, instead of in a table field
or query.
Note You can also use expressions in a form or report when you Highlight data
with conditional formatting.
Text operations
The expressions in the following table use the & (ampersand) and the + (plus)
operators to combine text strings, built-in functions to manipulate a text string, or
otherwise operate on text to create a calculated control.
Expression Result
spaces.
Top of Page
Expression Result
=[Page] 1
=[Page] & "/" & [Pages] & " Pages" 1/3 Pages
Expression Result
Top of Page
Arithmetic operations
You can use expressions to add, subtract, multiply, and divide the values in two or
more fields or controls. You can also use expressions to perform arithmetic
operations on dates. For example, suppose you have a Date/Time table field
named RequiredDate. In the field, or in a control bound to the field, the
expression =[RequiredDate] - 2 returns a date/time value equal to two days
before the current values in the RequiredDate field.
Expression Result
Top of Page
The following table lists examples of expressions that you can use in calculated
controls on forms.
Expression Result
The expressions in the following table show some ways to use calculated controls
on reports. The expressions reference the Report Property.
Expression Result
subreport.
Top of Page
The expressions in the following table show some of the ways to use functions
such as Avg, Count, and Sum.
Expression Description
expression.
For more information about using aggregate functions and totaling the values in
field and columns, see the articles Sum data by using a query, Count data by using
a query, Display column totals in a datasheet using a Totals row, and Display
column totals in a datasheet.
Top of Page
Expression Description
value of
the
SupplierID
field in the
table
matches
the value
of the
SupplierID
control on
the
Suppliers
form.
Expression Description
SupplierID
field in the
table
matches
the value
of the
SupplierID
control on
the New
Suppliers
form.
function to
return the
sum total
of the
values in
the
OrderAmo
unt field in
the Orders
table
where the
CustomerI
D is RATTC.
Expression Description
Date operations
Tracking dates and times is a fundamental database activity. For example, you can
calculate how many days have elapsed since the invoice date to age your accounts
receivable. You can format dates and times in numerous ways, as shown in the
following table.
Expression Description
Top of Page
Conditions of only two values
The example expressions in the following table use the IIf function to return one of
two possible values. You pass the IIf function three arguments: The first argument
is an expression that must return a True or Falsevalue. The second argument is
the value to return if the expression is true, and the third argument is the value to
return if the expression is false.
Expression Description
is Yes; otherwise, it
displays the
message "Order
Not Confirmed."
control.
controls.
and ShippedDate
controls.
Top of Page
Text operations
The expressions in the following table use the & and + operators to combine text
strings, use built-in functions to operate on a text string, or otherwise operate on
text to create a calculated field.
Expression Description
Top of Page
Arithmetic operations
You can use expressions to add, subtract, multiply, and divide the values in two or
more fields or controls. You can also perform arithmetic operations on dates. For
example, suppose you have a Date/Time field called RequiredDate. The
expression =[RequiredDate] - 2 returns a Date/Time value equal to two days
before the value in the RequiredDate field.
Expression Description
to Expression.
If you set
the Format property of
the field to Percent, do
not include *100.
For more information about using aggregate functions and totaling the values in
field and columns, see the articles Sum data by using a query, Count data by using
a query, Display column totals in a datasheet using a Totals row, and Display
column totals in a datasheet.
Top of Page
Date operations
Nearly all databases store and track dates and times. You work with dates and
times in Access by setting the date and time fields in your tables to the Date/Time
data type. Access can perform arithmetic calculations on dates; for example, you
can calculate how many days have elapsed since the invoice date to age your
accounts receivable.
Expression Description
Top of Page
To calculate totals, you will often need to create a totals query. For example, to
summarize by group, you need to use a Totals query. To enable a Totals query
from the query design grid, click Totals on the View menu.
Expression Description
(blank) fields.
function.)
Top of Page
Expression Description
CountryRegion field.
Top of Page
Expression Description
same as the
CategoryID
from the
Products
table.
Top of Page
to display orders
shipped to
Canada or the UK.
the * wildcard
character to
display products
whose names do
not begin with C.
Top of Page
Match date criteria
The expressions in the following table demonstrate the use of dates and related
functions in criteria expressions. For more information about entering and using
date values, see the article Format a date and time field.
of each month.
Top of Page
Top of Page
"ar".
Top of Page
Match rows with SQL aggregates
You use an SQL or domain aggregate function when you need to sum, count, or
average values selectively. For example, you might want to count only those values
that fall within a certain range, or that evaluate to Yes. At other times, you might
need to look up a value from another table so that you can display it. The sample
expressions in the following table use the domain aggregate functions to perform
a calculation on a set of values, and use the result as the query criteria.
Top of Page
Top of Page
Update queries
You use an update query to modify the data in one or more existing fields in a
database. For example, you can replace values or delete them entirely. This table
demonstrates some ways to use expressions in update queries. You use these
expressions in the Update To row in the query design grid for the field that you
want to update.
For more information about creating update queries, see the article Create and run
an update query.
number.
e 5) leftmost
characters,
leaving the
five rightmost
characters.
Top of Page
SQL statements
Structured Query Language, or SQL, is the query language that Access uses. Every
query that you create in query Design view can also be expressed by using SQL. To
see the SQL statement for any query, click SQL View on the View menu. The
following table shows sample SQL statements that employ an expression.
displays it in a field
named Average
Extended Price.
Top of Page
Table expressions
The two most common ways to use expressions in tables are to assign a default
value and to create a validation rule.
Quantity 1 1
Region "MT" MT
Region "New York, New York, N.Y. (Note that you must
N.Y." enclose the value in quotation marks if
it includes punctuation.)
Date
Top of Page
The examples in the following table demonstrate the validation rule expressions for
the ValidationRule property and the associated text for
the ValidationText property.
For more information about validating data, see the article Create a validation rule
to validate data in a field.
Top of Page
Macro expressions
In some cases, you might want to carry out an action or series of actions in a macro
only if a particular condition is true. For example, suppose you want an action to
run only when the value of the Counter text box is 10. You use an expression to
define the condition in the Condition column of the macro:
[Counter]=10
value of the
TotalOrds field on
the SalesTotals form
is greater than 100.
long.
Top of Page