Protect Access VBA Code Project

How do I prevent user from changing the design or VBA code in an Access Database

Protecting VBA Code in an Access Database?


Return to FAQs

To ensure that users cannot access or change VBA code in Microsoft Visual Basic Applications (including Microsoft Access Database) two options are available to you:

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 enough 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 your database has been protected you will need the password to open or edit VBA modules in the database. Follow theses steps to password protect the vba code in your database.

  1. Open the Access Database (ensuring you are the only user of the database)
  2. In Access, press ALT+F11 to open the VBA editor.
  3. On the Tools menu, select {the Database Name} Properties (in this case the project name is RECIPES. NOTE: the project name may not always match the database name.).
  4. Access Database - Access VBA Project window screen shot
  5. On the Protection tab, select the ‘Lock project for viewing’ check box.
  6. VBA Project Password panel in properties window
  7. Enter and confirm your password and then click 'OK'
  8. To confirm the VBA project is passworded, close and reopen the database. Double click on any module to open it. You should be prompted to enter the VBA password.
  9. Enter VBA Project Password to edit modules
  10. You will only need to enter the password once each session, until you close the database.

Return to FAQs