ACC2000: Syntax Error When You Convert a Macro to Visual Basic for Applications Code (253259)



The information in this article applies to:

  • Microsoft Access 2000

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.

MORE INFORMATION

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.

  1. Open the sample database, Northwind.mdb.
  2. In the Database window, click Macros under Objects, and then click New.
  3. Create the following macro called macTestConvert:
       Action
       --------------------------------
       SetValue
    
       macTestConvert Action Arguments
       -------------------------------
       Item: Forms![Customer Orders]![CompanyName]
       Expression: "Test"
    					
  4. Save and close the macro.
  5. Select the macTestConvert macro in the Database window. On the Tools menu, point to Macro, and then click Convert Macros to Visual Basic.
  6. 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.
  7. 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.
  8. On the Debug menu, click Compile Northwind. Note that you receive a syntax error on the first line of the converted macro.

Modification Type:MajorLast Reviewed:6/30/2004
Keywords:kbbug KB253259