About securing Visual Basic for Applications code in Access projects

Protecting VBA code

In a Microsoft Access project (.adp), you can protect all modules, and modules behind forms and reports, by protecting Visual Basic for Applications (VBA) code with a password that you and other users must enter to view or edit VBA code in the Visual Basic Editor. Once you set a password, you enter this password once per session. The password is required not only for viewing and editing, but also for cutting, copying, pasting, exporting, and deleting any module. Note, however, that protecting your VBA code in this manner doesn't prevent you or other users from running existing VBA code.

About .ade files

If your Microsoft Access project contains Visual Basic for Applications (VBA) code, saving your Access project as an .ade file compiles all modules, removes all editable source code, and compacts the destination Access project file. Your VBA code will continue to run, but it cannot be viewed or edited.

Your Access project file will continue to function normally ù you can still update data and run reports. Additionally, the size of your Access project will be reduced due to the removal of the code, so memory usage is optimized, which will improve performance.

Saving your Access project file as an .ade file prevents the following actions:

Considerations if you need to modify the design of forms, reports, or modules

Be sure to save a copy of your original Access project file. If you need to modify the design of forms, reports, or modules in an Access project file that you have saved as an .ade file, you must modify the original Access project, and then resave it as an .ade file.

You won't be able to open, convert, or run code in an Access 2002 .ade file in future versions of Access. The only way to convert an Access 2002 .ade file to a future version will be to open the original Access project that the .ade file was created from, convert it to the later version of Access, and then save the converted Access project file as an .ade file.

Considerations before saving your Access project file as an .ade file

Some restrictions may prevent you from saving your Access project file as an .ade file:

About references and .ade files

If you try to create an .ade file from an Access project file or an add-in that references another Access project or add-in, Access displays an error message and doesn't let you complete the operation. To save an Access project that references another Access project as an .ade file, you must save all projects in the chain of references as .ade or .mde files, starting from the first project referenced. After saving the first project as an .ade or .mde file, you must then update the reference in the next project to point to the new file before saving it as an .ade file, and so on.

For example, if Project1.adp references Project2.adp, which references Project3.mda, you would proceed as follows:

  1. Save Project3.mda as Project3.mde.
  2. Open Project 2.adp and change its reference to point to the new Project3.mde.
  3. Save Project2.adp as Project2.ade.
  4. Open Project1.adp and change its reference to point to the new Project2.ade.
  5. Save Project1.adp as Project1.ade.

About securing .ade files

A Microsoft Access project can't use the same user-level security features that a Microsoft Access database (.mdb) can. The data and other objects stored on your SQL Server must be secured by using SQL Server's security features.

To secure access to the VBA code in an Access project, you must password-protect its VBA project or remove your VBA source code by saving your Access project file as an .ade file. To secure access to the design of forms and reports in an Access project file, you can set startup options or save your Access project file as an .ade file. The only way to secure access to macros in an Access project file is by setting startup options.