Microsoft KB Archive/163842

= ACC: Compile Error After Converting Form Macros to VBA =

Article ID: 163842

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q163842



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



SYMPTOMS
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.

In Microsoft Access 97

The expression  you entered as the event property setting produced the following error: Ambiguous name detected: .

In Microsoft Access 7.0

The expression  you entered as the event property setting produced an error: Compile error.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.



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
In Microsoft Access 97, 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.
 * 1) 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
In Microsoft 7.0 and 97, 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 (or the Run menu in version 7.0), click Compile Loaded Modules. You will receive the error "Ambiguous name detected: ."
 * 4) Page up and down through the class module, looking for another procedure with the same name as the one that produced the compile error. When you find it, determine which procedure is the converted macro and which is the old procedure.
 * 5) Select and delete the old 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.  Start Microsoft Access and open the sample database Northwind.mdb.  Create the following new macro called TestVBA:   Macro Name     Action ---  TestVBA        Maximize  Save the macro and close it.</li> Use the AutoForm: Columnar Wizard to create a new form based on the Shippers table.</li> Save the form as frmShippers, and then open it in Design view.</li>  Set the OnLoad property of the form to the following event procedure: Private Sub Form_Load 'This module will be replaced by a macro End Sub </li> Close the form's Module window.</li> Change the OnLoad property of the form from [Event Procedure] to TestVBA.</li> On the Tools menu, point to Macro (or Macros in version 7.0), and then click "Convert Form's Macros to Visual Basic."</li> In the Convert Form Macros dialog box, click Convert.</li> After conversion finishes, switch the form to Form view. Note that you receive the error message. If you browse the form's class module, you notice there are two procedures named Form_Load.</li></ol>

<div class="references_section">