Microsoft Office Tutorials and References
In Depth Information
Writing Your Own VBA Procedures
FormName refers to that passed string within the function. The function
returns either a True or False value (the Boolean data type).
Function IsOpen(FormName As String) As Boolean
... code ...
End Function
Don’t bother to type either of the preceding procedures, because they don’t
actually do anything. They just demonstrate the syntax of the Sub and
Function statements. Figure 2-9 further points out the purposes of the
various components of the sample Function statement.
Figure 2-9:
of a sample
Returning a value from a function
Any function can return a value. To define the value that a function returns,
you use the following syntax within the body of the function:
functionName = value
functionName is the name of the function, and value is the value that the
function returns. Following is an example:
Function WithTax(AnyNumber As Currency) As Currency
WithTax = AnyNumber * 1.065
End Function
Chapter 2
Multiplying a number by 1.065 is equivalent to adding 6.5 percent sales tax
to that number. Do this little trick with any sales tax rate. To add 7.75 percent
sales tax, for example, you would multiply by 1.0775.
The WithTax() function is a complete VBA procedure that actually works.
If you type it in a standard module, you can use it anywhere in your database
just as you would a built-in function. You could even test it in the Immediate
window. After you type the WithTax function in the Code window, for
example, you can type the following in the Immediate window and press Enter:
? WithTax(10)
Search JabSto ::

Custom Search