Microsoft Office Tutorials and References
In Depth Information
Testing and Running Your Code
The following example custom function accepts no arguments and returns
the day of the week when it’s called:
Function Today() As String
Today = WeekDayName(Weekday(Date))
End Function
To test the function, type the following in the Immediate window and press
? Today()
The Immediate window displays the value returned by the function. If you
ran the test on a Monday, the function would return
The following function procedure accepts a single number as an argument
(and returns a number):
Function Area(radius As Double) As Double
Area = 3.141592654 * (radius ^ 2)
End Function
To test the function, call it with the ? symbol and pass some number to it, as
in this example:
? Area(10)
The Immediate window displays the value returned by the function, as the
following shows:
If the function accepts multiple arguments, you just separate the arguments
with commas, as you do when using the Access built-in functions.
Chapter 2
Using function procedures in Access
When you create a function procedure in VBA, you can use that function
anyplace within the database where you use a built-in function. Wherever you
use an expression in Access, that expression can contain built-in functions,
custom function procedures, or both. Here are some examples:
In an expression used in the Control Source property of a calculated
control on a form or a report
In an expression that defines a calculated field in a select query
In an expression in the Update To row of an update query
Search JabSto ::

Custom Search