Microsoft KB Archive/253259

= ACC2000: Syntax Error When You Convert a Macro to Visual Basic for Applications Code =

Article ID: 253259

Article Last Modified on 6/30/2004

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q253259



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

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).



SYMPTOMS
When you convert a macro to Visual Basic for Applications (VBA) and the macro contains a form reference that requires brackets, you may receive a syntax error when you run or compile the converted code.



CAUSE
The expression that contains the form reference has been split on two separate lines, for example: Forms![Customer Orders]!CompanyName

= "This is a test"



RESOLUTION
To avoid this problem, rename the form so that it does not require brackets before you convert the macro. Realize, however, that if you rename the object, you may also have to change the references to the object in the macro and other objects.

To correct this problem after the macro has been converted, edit the converted code so that the expression is on one line.



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



Steps to Reproduce the Behavior
CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

 Open the sample database, Northwind.mdb. In the Database window, click Macros under Objects, and then click New.  Create the following macro called macTestConvert:   Action SetValue

macTestConvert Action Arguments ---  Item: Forms![Customer Orders]![CompanyName] Expression: "Test"  Save and close the macro.</li> Select the macTestConvert macro in the Database window. On the Tools menu, point to Macro, and then click Convert Macros to Visual Basic.</li> Leave the default selections in the Convert Macro dialog box, and then click Convert. Click OK to the message confirming the completion of the conversion.</li> In the Database window, click Modules under Objects, and then double-click the Converted Macro-macTestConvert module to open it. Note that the expression has been split on two separate lines and appears in red.</li> On the Debug menu, click Compile Northwind. Note that you receive a syntax error on the first line of the converted macro.</li></ol>

Additional query words: pra

Keywords: kbbug KB253259

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.