1080
Part IV: Professional Database Development
FIGURE 30.23
The newly converted module
When you open the VBA editor for the new module, you can view the procedure created from the
macro. Figure 30.23 shows the mcrHelloWorldEnhanced function that Access created from
the mcrHelloWorldEnhanced macro.
At the top of the function, Access inserts four comment lines for the name of the function. The
Function statement follows the comment lines. Access names the function, using the macro
library’s name (mcrHelloWorldEnhanced).
When you specify that you want Access to include error processing for the conversion, Access
automatically inserts the On Error statement as the first command in the procedure. The On
Error statement tells Access to branch to other statements that display an appropriate message
and then exit the function.
The statement beginning with DoCmd is the actual code that Access created from the macro. The
DoCmd methods run Access actions from VBA. An action performs important tasks, such as closing
windows, opening forms, and setting the value of controls.
If you’re new to VBA and want to learn code, a good starting point is converting your macros to
modules. Just save your macros and modules, and then look at the VBA code to become familiar
with the syntax. The new macro features in Access 2007 and 2010 makes it harder to decide
whether to use macros or VBA.