Microsoft Office Tutorials and References
In Depth Information
Writing Expressions in Access
Using functions in expressions
Wait — there’s more. An Access expression can also contain any number of
functions. A function is sort of like an operator in that it performs some
calculation and then returns some value. The way that you use a function is
different, though: Every function includes a name followed by a pair of parentheses.
The Date() function, for example, always returns the current date.
Many functions accept arguments, which are enclosed within the
parentheses. To calculate the square root of a number, you use the Sqr() function.
The Sqr() function accepts one parameter: a number, the name of a field,
or an expression that contains a number. The Sqr() function returns the
square root of whatever value passes to it as an argument.
The following expression returns 9 because the square root of 81 is 9
(because 9 times 9 is 81). In this example, we use a number as the argument
to the Sqr() function:
Sqr(81)
Note that in the example, we use 81 as the argument to the Sqr() function.
Another way to state this is to say that we pass the number 81 to the
function. In other words, the term pass in this context means “to use as an
argument in a function.”
Book III
Chapter 2
The following Sqr() function uses an expression (5*20) as its argument:
Sqr(5*20)
Because the expression, 5*20, is inside the parentheses, the
multiplication happens first. For an instant, the function contains Sqr(100). Then
Sqr(100) returns 10 because 10 is the square root of 100.
You can use field names in functions as well. Suppose that you have a
table that contains a number field named bigNumber. The following
Sqr() function returns the square root of whatever value is stored in the
bigNumber field:
Sqr([bigNumber])
Dozens of functions are built into Access. In fact, memorizing all the
functions is nearly impossible. We recommend looking up functions as you need
them, using Expression Builder as your guide. What’s Expression Builder?