Previous Page

Compiling and Saving Your Code Ahead of Time

The code in all modules is saved as source code and compiled code. Source code consists of the Visual Basic code you write in text form including declarations, procedure names, variable names, comments, blank lines, and spaces. Microsoft Access converts the source code you write through a process called compiling into a form that it uses to run your application. If you don't explicitly compile your code by using the Compile And Save All Modules command (Debug menu), Microsoft Access must compile your code and load it into memory once for every user of your database. To avoid this, you should compile and save your code when you are ready to distribute your application to users, and before you do any performance testing with your application.

   To compile and save the code in all modules in your application

1   Open any module or the Debug window.

2   On the Debug menu, click Compile And Save All Modules.

Tip   Only use the Compile And Save All Modules command when you are ready to distribute your application or check its performance. While you are developing your application, it will become decompiled (lose its fully compiled state) frequently. As a result, using the Compile And Save All Modules command during development wastes time. To quickly compile and check the syntax of code in changed modules without taking the time to compile modules that have not changed, use the Compile Loaded Modules command (Debug menu).

Avoiding Decompiled Code

If you or the users of your application make certain changes to it, some of your application's code may become decompiled, which means that Microsoft Access must recompile those portions before running them.

Changes Made to Objects That May Decompile Code

Any of the following actions made to objects within a compiled database can decompile some of the code in your database:

 Adding a new form, report, control, or module

 Modifying the code in a form, report, control, or module

 Deleting or renaming a form, report, control, or module

 Adding or removing a reference to an object library or database by using the References command (Tools menu)

If the users of your application don't need to perform these actions, you can ensure that your application runs as efficiently as possible by compiling your application with the Compile And Save All Modules command before you deliver it and after you make any subsequent changes to it. To prevent users from making changes that decompile the code in your application after you deliver it, you can save it as an MDE file, or establish user-level security.

See Also   For more information on MDE files and user-level security, see Chapter 14, "Securing Your Application"

Separating Decompiled Code from Standard Modules

If your users are likely to decompile your application's code, and if a significant portion of your code resides in standard modules, you can improve your application's performance by moving your standard modules to a library database. Then, establish a reference from your application to the new library database. Now when users open a form containing decompiled code, your application only needs to compile that code and can quickly open the library database containing the fully compiled code from your standard modules. Also, users can add new forms and reports without decompiling the code in the library database. Establishing a reference to a library database creates some additional memory overhead, so this method is most effective for applications with a significant amount of standard module code.

See Also   For more information on library databases, see Chapter 12, "Using Library Databases and Dynamic-Link Libraries."

Changes Made to Databases That Decompile Code

In Microsoft Access 95, the following actions decompile the code in a database:

 Renaming the database

 Compacting or repairing the database to a different name

 Copying the database to a new name (in this case, the copy is decompiled, not the original)

This occurs because in Microsoft Access 95, the name of the database is used as the Visual Basic for Applications project name. The project name is used to identify all the compiled code in a database. In Microsoft Access 95, performing any action that changes the name of a database containing compiled code effectively changes the name of the project and decompiles the code.

These same changes do not decompile code in a Microsoft Access 97 database, because you can explicitly give your application a project name. To give your application a project name, click Options on the Tools menu, click the Advanced tab, and then type the name in the Project Name box. By default, when you create a new database, Microsoft Access 97 uses the name of the database for the project name. Whether you specify a custom project name or accept the default project name, if you perform any action that changes the name of the database, the project name doesn't change and cause code to be decompiled. However, if you compile your application, and then change the project name by using the Project Name box in the Options dialog box, your code is decompiled.

© 1996 Microsoft Corporation. All rights reserved. Next Page


Casa de Bender