Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 10: VBA Programming Fundamentals


383


as you review every macro in your macro libraries. You can’t cut and paste a macro into a VBA
code module. You have to analyze the task accomplished by each macro action, and then add the
equivalent VBA statements to your code.

Fortunately, Access provides a feature to convert macros to VBA code automatically. One of the
options in the Save As dialog box is Save As Module. You can use this option when a macro file is
highlighted in the Macros object area of the Solution Explorer. This option enables you to convert
an entire macro group to a VBA module in seconds.

To try the conversion process, save the mcrOpenContacts macro in the Chapter10.accdb
database as a module by following these steps:


  1. Open the Macros section of the Navigation Pane, and s elect the mcrOpenContacts
    macro.

  2. Click the File button in the upper-left corner of the main Access window to open the
    Backstage, and select Save As from the command list.


The Save As dialog box appears, as shown in Figure 10.1.


FIGURE 10.1
Saving a macro as a module


  1. Select Module from the drop-down list on the Save As dialog box.


Access assigns a default name for the new module as Copy of followed by the macro
name. Oddly enough, when you save a macro as a VBA module, Access doesn’t use the
name displayed in the Save As dialog box, nor does it use any name that you enter in the
Save As dialog box.


The Convert Macro dialog box appears, as shown in Figure 10.2.


FIGURE 10.2
The Convert Macro dialog box
Free download pdf