Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Convert Macros to Visual Basic for Applications Code


View products that this article applies to.

Summary

You can do a lot with macros. You can open and close forms, show and hide toolbars, and run reports. However, if you want more control over your application's behavior, you can convert your macros to Visual Basic for Applications code. To help you convert existing macros to Visual Basic for Applications code, you can use the Microsoft Access Macro Conversion Wizard. This article explains how to use the Macro Conversion Wizard, and how it converts your macro actions.

↑ Back to the top


More information

To convert a macro to Visual Basic for Applications code, follow these steps:
  1. Start Microsoft Access and open the sample database Northwind.mdb.
  2. In the Database window, click Macros under Objects, and select a macro, for example, Customer Labels Dialog.
  3. On the File menu, click Save As.
  4. Under As in the Save As box, select Module, and then click OK.
  5. In the Convert macro box, click to select the Add error handling to generated functions and the Include macro comments check boxes.
  6. Click Convert.
The Macro Conversion Wizard does the following when it converts a macro to Visual Basic code:
  • It creates a new module of procedures using the names from the Macro Names column in the original macro.
  • It converts macro actions to appropriate DoCmd methods in Visual Basic. For the several macro actions that do not have a DoCmd equivalent, the Macro Conversion Wizard does the following:
       No DoCmd Equivalent    Solution
       -----------------------------------------------------------------------
    
        AddMenu               The wizard comments out these lines in the code
                              and notifies the user.
    
        MsgBox                Uses the MsgBox function.
    
        RunApp                Uses the Shell function to run another
                              application.
    
        RunCode               Uses the Call statement, and runs the function
                              directly in Visual Basic.
    
        SendKeys              Uses the SendKeys statement.
    
        SetValue              Sets the value directly in Visual Basic.
    
        StopAllMacros         Uses the End statement.
    
        StopMacro             Uses the Exit Function statement.
    					
  • It converts expressions in the macro's Condition column to If...Then statements.
  • If the Condition column contains a full reference to a control in a form or report (for example, Forms!MyForm![LastName]), Microsoft Access uses If...Then statements. If the reference refers to a control name only (for example, [LastName]), Access uses a With...End With or a CodeContextObject statement.

↑ Back to the top


References

For more information about converting macros to Visual Basic forApplications code, click Microsoft Access Help on the Help menu, type convert macros to microsoft visual basic in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB210245, kbprogramming, kbhowto

↑ Back to the top

Article Info
Article ID : 210245
Revision : 4
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 336