Microsoft KB Archive/275121

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

Article ID: 275121

Article Last Modified on 11/6/2003

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



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:  In an earlier version of Microsoft Access, such as Access 2000, open a database.  Create a module, and then add the following code: Sub Test MsgBox &quot;Test&quot; End Sub  Compile the project, and then save the module as Module1.  In the Immediate window, type the following line, and then press ENTER: ?Application.IsCompiled This returns a value of True.  Close the database.</li> Open the same database in Access 2002.</li>  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. </li> To test this even further, close the database, and reopen the database using the same earlier version of Access.</li>  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. </li></ol>

Additional query words: pra prb

Keywords: kbprb kbpending KB275121

-

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

© Microsoft Corporation. All rights reserved.