Sometimes you will create a macro, later to discover
that you want to convert it to VBA code. Fortunately, Access 2010 comes
to the rescue. You can easily convert an Access macro to VBA code; after
the macro has been converted to VBA code, the code can be modified just
like any VBA module. Follow these four steps to convert an Access macro
to VBA code:
1. | Open the macro you want to convert in Design view.
|
2. | Select
Convert Macros to Visual Basic in the Tools group on the Macro Tools
Design tab of the Ribbon. The Convert Macro dialog appears (see Figure 1).
|
3. | Determine
where you want to add error handling and comments to the generated
code, and then click Convert. Access informs you that the conversion
finished and places you in the Visual Basic Editor - VBE (see Figure 2).
|
4. | The converted macro appears under the list of modules with Converted Macro: followed by the name of the macro. Click Design to view the results of the conversion.
|
Figure 3
shows a macro that’s been converted into distinct subroutines, one for
each macro name. The macro is complete with logic, comments, and error
handling. All macro conditions are converted into If...Else...End If
statements, and all the macro comments are converted into VBA comments.
Basic error-handling routines are automatically added to the code.
When you convert a macro
to a Visual Basic module, the original macro remains untouched.
Furthermore, all the objects in your application will still call the
macro. To effectively use the macro conversion options, you must find
all the places where the macro was called and replace the macro
references with calls to the VBA function.