Protecting VBA Code in an Access Database?
To ensure that users cannot access or change VBA code in Microsoft Visual Basic Applications (including Microsoft Access Database) you have two options available for doing so:
1. Save the database in a compile format (MDE or ACCDE). (See our FAQ Converting Access Database to ACCDE/MDE)
2. Password protect the VBA code in your database. (Be aware VBA Passwords can be defeated, but is usually enought to keep standard user's out of your code)
Compiling an Access Database
When you compile a Microsoft Access Database into accde or mde format, the database remains functional and users can run the database as normal. However, in a compiled database format (either mde or accde) database users no longer have access to the design functionality to change the format or appearance of forms and reports, nor can user's view the VBA code behind form modules or general VBA modules.
If you do no want users to edit and change the design of forms/reports then you should provide them with a database in a compiled mde or accde format.
How to Password Protect the VBA Code
When you password protect the VBA project in an Access database, the database remains fully functional and users can operate the database as normal, and also edit and even change the physical appearance and other properties of Forms and Reports. However, users cannot access, view, or edit any VBA module in the database, including the code-behind forms/reports and general modules unless they know and provide the VBA protection password.
To password protect the VBA code, make a BACKUP copy of your database. Make a note of the PASSWORD you intend to use to protect your VBA project and put it in a safe place. Once the VBA project code in yor database has been protected you will need the password to open VBA modules in the database. Follow theses steps to password protect the vba code in your database.
- Open the Access Database (ensure are the only user in the database)
- In Access, press ALT+F11 to open the VBA editor.
- On the Tools menu, select
Properties (in this case the project name is RECIPES, but note that the project name may not always match the database name).
- On the Protection tab, select the ‘Lock project for viewing’ check box.
- Enter and confirm your password and then click 'OK'
- To confirm the VBA project is passworded, close and reopen the database. Doulble click on any module to open it. You should be propmted to enter the VBA password.
- You will only need to enter the password once each session, until you close the database.