Microsoft Knowledge Base Email Alertz

(824180) - Describes an issue that when you convert a macro to a module and then try to compile the module, the compilation may not be successful. This issue only occurres when a macro contains a condition and the condition statement refers to a database object.

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 824180 - Last Review: April 12, 2007 - Revision: 2.1

Compilation is not successful when you convert a macro to a module in Microsoft Access

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

This article applies to a Microsoft Access database (.mdb) file or to a Microsoft Access database (.accdb) file.

On This Page

SYMPTOMS

In Microsoft Access, when you convert a macro to a module, and you then try to compile the module, the compilation may not be successful. You may see this problem only when the macro contains a condition and when that condition statement refers to a form or to any database object.

CAUSE

This problem occurs when the condition that is specified in the macro refers to a form or to a database object and the name of the object contains spaces. The spaces in the name of the object introduce an extra line when the macro is converted to a module. Because of this, the compilation of the module is not successful.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

WORKAROUND

To work around the problem that is described in the "Symptoms" section, open the module that is created when the macro is converted to a module, and then delete the extra space or line from the name of database object. Replace the code sample that is provided in "More Information" section of this article with the following code:
Function Macro1_TestMacro()
On Error GoTo Macro1_TestMacro_Err

    If (Forms![Orders Subform]!Product = "Pavlova") Then
        Forms![Orders Subform]!Product.Enabled = True
    End If


Macro1_TestMacro_Exit:
    Exit Function

Macro1_TestMacro_Err:
    MsgBox Error$
    Resume Macro1_TestMacro_Exit

End Function
  

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Open the Northwind sample database in Access.
  2. In the Database window, click Macros under Objects, and then click New.

    Note In Access 2007, click Macro in the Other group on the Create tab.
  3. On the View menu, click Macro Names, and then click Conditions.

    Note In Access 2007, make sure that Macro Names, Show All Actions and Conditions are selected in the Show/Hide group on the Design tab.
  4. In the Macro Name column, type TestMacro.
  5. In the Condition column, type the following:
    [Forms]![Orders Subform]![Product]="Pavlova"
  6. In the Action column, select SetValue from the list.
  7. In the Action Arguments pane, set Expression to Yes, and then set Item to the following:
    [Forms]![Orders Subform]![Product].[Enabled]
  8. On the File menu, click Save As.

    Note In Access 2007, click Microsoft Office Button, and then click Save As.
  9. In the Save as dialog box, click OK.
  10. On the File menu, click Save As.

    Note In Access 2007, click Microsoft Office Button, and then click Save As.
  11. In the Save as dialog box, select Module from the As list box, and then click OK.
  12. In the Convert macro: Macro1 dialog box, click Convert.
  13. In the Conversion Finished message box, click OK.
  14. In the Database window, click Modules under Objects.

    Note In Access 2007, click the Module group in the left navigation pane.
  15. Double-click Converted Macro-Macro1 to open the macro.
After you run the code, the code is modified as follows, and the debugger shows the error in the If statement in red:
Function Macro1_TestMacro()
On Error GoTo Macro1_TestMacro_Err

    If (Forms![Orders Subform]!Product
                                                                                                                                                                                                                                                               
           = "Pavlova") Then
        Forms![Orders               Subform]!Product.Enabled = True
    End If


Macro1_TestMacro_Exit:
    Exit Function

Macro1_TestMacro_Err:
    MsgBox Error$
    Resume Macro1_TestMacro_Exit

End Function
  

APPLIES TO
  • Microsoft Office Access 2007
  • Microsoft Office Access 2003
  • Microsoft Access 2002 Standard Edition
Keywords: 
kbexpertiseinter kbtshoot kbprogramming kbmacro kbprb KB824180
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate