ACC: Writing Functions Called from Events or ExpressionsID: Q97514
|
Moderate: Requires basic macro, coding, and interoperability skills.
Functions can be used in a variety of places in Microsoft Access. How
you write your functions depends on where the functions are going to
be called from.
This article assumes that you are familiar with Access Basic and with
creating applications for Microsoft Access using the programming tools
provided with Microsoft Access.
There are two main styles for writing Access Basic functions:
Function ProperAU(Field As Control)
Field=UCase(Left(Field,1)) & LCase(Mid(Field,2))
End Function
NOTE: The result of the calculation updates the field that was
passed as a parameter.
Object: Text Box
----------------
ControlName: First Name
AfterUpdate: =ProperAU([First Name])
Function ProperCC(Field)
ProperCC=UCase(Left(Field,1)) & LCase(Mid(Field,2))
End Function
NOTE: The result of the calculation is assigned to the function.
This way, it can be used in an expression or calculated control.
Object: Text Box
----------------
ControlName: Proper Last Name
ControlSource: =ProperCC([Last Name])
Now, when you type in the Last Name field, you will see the correct
capitalization in the Proper Last Name field.
Where used Function style
-----------------------------------------------------------
AfterUpdate, BeforeUpdate, and so on Event
RunCode macro action Event
Calculated controls on forms and reports Expression
Calculated fields in a query Expression
SetValue macro action expression Expression
Default values in a table or form Expression
Called from another function or sub Expression
Additional query words:
Keywords : kbprg
Version : WINDOWS:1.0,1.1,2.0
Platform : WINDOWS
Issue type : kbinfo
Last Reviewed: July 13, 1999