ACC2000: Compile Error After Converting Form Macros to VBA

ID: Q209907


The information in this article applies to:
  • Microsoft Access 2000


SYMPTOMS

Moderate: Requires basic macro, coding, and interoperability skills.

After you convert macros to Visual Basic for Applications code in a form or report by using the "Convert Macros to Visual Basic" command, you may receive the following error message when you use the form or report.

The expression <Event Name> you entered as the event property setting produced the following error: Ambiguous name detected: <Procedure Name>.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp


CAUSE

At one time, the form or report had an event procedure that was later changed to a macro.


RESOLUTION

To prevent the error, open a form or report class module in Design view and delete the procedure for the event whenever you replace an event procedure with a macro.

To resolve the error, use one of the following methods to remove the duplicate procedure in the object's class module.

Method 1

If the object does not contain a mixture of Visual Basic code and macros, you can remove the object's class module before you convert its macros:

  1. Open the form or report in Design view.


  2. Set the object's HasModule property to No, and then save the object.

    NOTE: Any Visual Basic code that the object contains is removed along with its class module when you set the HasModule property to No.


  3. On the Tools menu, point to Macro, and then click Convert Form's Macros to Visual Basic or Convert Report's Macros to Visual Basic.

    A new class module is created for the object and no duplicate procedure names exist.


Method 2

You can open the object's class module in Design view and remove the duplicate procedure:
  1. Open the object in Design view.


  2. On the View menu, click Code.


  3. On the Debug menu, click Compile <DBname>. You will receive the following error message:


  4. Ambiguous name detected: <Procedure Name>.
  5. Look through the class module, looking for another procedure with the same name as the one that produced the compile error.


  6. Select and delete the unwanted procedure.



MORE INFORMATION

When you replace [Event Procedure] with the name of a macro in Design view of a form or report, the procedure itself remains in the object's class module. When you convert the macro to a Visual Basic procedure, the wizard does not check to see if a procedure for that event already exists, and it creates a duplicate procedure.

Steps to Reproduce Behavior

The following example uses a form. You can obtain the same results by using a report.
  1. Start Microsoft Access and open the sample database Northwind.mdb.


  2. Create the following new macro called TestVBA:


  3. Macro Name Action
    TestVBA Maximize
  4. Save the macro and close it.


  5. Use the AutoForm: Columnar Wizard to create a new form based on the Shippers table.


  6. Save the form as frmShippers, and then open it in Design view.


  7. Set the OnLoad property of the form to the following event procedure:


  8. 
    Private Sub Form_Load()
        'This module will be replaced by a macro
    End Sub 
  9. Close the form's Module window.


  10. Change the OnLoad property of the form from [Event Procedure] to TestVBA.


  11. On the Tools menu, point to Macro, and then click Convert Form's Macros to Visual Basic.


  12. In the Convert Form Macros dialog box, click Convert.


  13. Click OK when the conversion finishes and switch the form to Form view.


NOTE: You receive the error message indicated in the Symptoms section. If you browse the form's class module, you will find two procedures named Form_Load.


REFERENCES

For more information about using the Covert Macros to Visual Basic command, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type "converting macros" in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Additional query words: prb

Keywords : kbdta FmsEvnt
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: July 6, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.