Microsoft Access 2010 Bible

(Rick Simeone) #1

Part I: Access Building Blocks


174


The parentheses around [Price] * [DiscountPercent] instruct Access to perform this oper-
ation before subtracting the multiplication result from [Price]. Without parentheses, Access may
process expressions from left to right, which would return an incorrect result. In this particular
case, because the order of precedence means that the multiplication takes place before subtraction,
but that may not always be the case. In most cases, it’s better to wrap operations you want to occur
first within parentheses, as shown in this example.

Note
Although parentheses are not mathematical operators, they play an important role in many expressions, as dis-
cussed in the “Operator precedence” section, later in this chapter.


The multiplication operator: *
A simple example of when to use the multiplication operator is to calculate the total price of sev-
eral items. You could design a query to display the number of items purchased and the price for
each item. Then you could add a calculated field containing the value of the number of items pur-
chased times the price per item. In this case, expression would be

[tblSalesLineItems].[Quantity] * [tblSalesLineItems].[Price]

Note
The standard Access notation for dealing with table names and field names in an expression is to enclose each
name in square brackets, and separate them with a period. For example:


[TableName].[FieldName]

Tip
Notice that you use the table name before the field name in the preceding example. Because only one table has
a field named Price and one other table has a field named Quantity, you could have skipped the table
names. However, specifying the name of the table containing the field and using a period to separate the table
name from the field name are good practices.


The division operator: /
Use the division operator to divide two numbers. Suppose, for example, that a pool of 212 people
win a $1,000,000 lottery. The expression to determine each individual’s payoff of $4,716.98 is

1000000 / 212

Note
Notice that the 1000000 value does not contain commas. Access is not able to perform a mathematical opera-
tion on numeric values containing punctuation.

Free download pdf