ACC2002: Visual Basic for Applications Code Is Decompiled When It Is Opened in an Earlier Version of Microsoft Access (275121)



The information in this article applies to:

  • Microsoft Access 2002

This article was previously published under Q275121
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 use Microsoft Access 2002 to open a database that was created in an earlier version of Microsoft Access, the database project is decompiled, even though no modifications were made to the underlying Visual Basic for Applications code.

CAUSE

As soon as you open the Visual Basic Editor, a project is automatically decompiled because of the TypeLib changes between Access 2002 and earlier versions of Access.

RESOLUTION

Recompile the Visual Basic for Applications project.

MORE INFORMATION

You would expect the project to remain compiled once it is deliberately compiled. However, if you open the Visual Basic for Applications project using a different version of Access than the one it was compiled in, the project is automatically decompiled, even if the code has not been modified.

When the VBA project is compiled, the application's object library is stored as part of the compiled project. So, if an Access 2000 database is opened in Access 2002, and the project is compiled, the Access 2002 object library is stored as part of the compiled project. If Access 2000 tried to load the compiled project, it would cause it to crash because the Access 2002 object library has many objects, methods, properties, and events that Access 2000 does not recognize.

To prevent this from happening, Access 2002 always increments the VBA project version when opening an Access 2000 database. This will cause Access 2000 to decompile the VBA project when it is later opened in Access 2000, thus avoiding any crash. The unfortunate side effect of this is that code may run more slowly in Access 2000 until you recompile in Access 2000.

Steps to Reproduce Behavior

The following steps show how a project is decompiled when a database that is created in an earlier version of Microsoft Access is opened by Access 2002:
  1. In an earlier version of Microsoft Access, such as Access 2000, open a database.
  2. Create a module, and then add the following code:
    Sub Test()
       MsgBox "Test"
    End Sub
    					
  3. Compile the project, and then save the module as Module1.
  4. In the Immediate window, type the following line, and then press ENTER:
    ?Application.IsCompiled
    						
    This returns a value of True.
  5. Close the database.
  6. Open the same database in Access 2002.
  7. Without modifying the code, open Module1 in Design view, type the following line in the Immediate window, and then press ENTER:
    ?Application.IsCompiled
    						
    This returns a value of False, proving that the code is decompiled simply by opening the code in the Visual Basic Editor.
  8. To test this even further, close the database, and reopen the database using the same earlier version of Access.
  9. Open Module1 in Design view, type the following line in the Immediate window, and then press ENTER:
    ?Application.IsCompiled
    						
    This returns a value of False, proving once again that the code has been decompiled.

Modification Type:MajorLast Reviewed:11/6/2003
Keywords:kbpending kbprb KB275121