Secure Visual Basic for Applications code in Access databases (MDB)

 Note   The information in this topic applies only to a Microsoft Access database (.mdb).

ShowSecure Microsoft Visual Basic for Applications code with a password

To prevent someone from viewing or making changes to your Microsoft Visual Basic for Applications (VBA) (Visual Basic for Applications (VBA): A macro-language version of Microsoft Visual Basic that is used to program Windows applications and is included with several Microsoft applications.) code, you can help protect the code by requiring a password.

  1. Open the Microsoft Access project (.adp) (Microsoft Access project: An Access file that connects to a Microsoft SQL Server database and is used to create client/server applications. A project file doesn't contain any data or data-definition-based objects, such as tables and views.) file or Microsoft Access database (.mdb) (database: A collection of data related to a particular subject or purpose. Within a database, information about a particular entity, such as an employee or order, is categorized into tables, records, and fields.) file that has the VBA code you want to help protect.
  2. In the Database window, point to Macro on the Tools menu, and then click Visual Basic Editor.


You can also press ALT+F11.

  1. In the Microsoft Visual Basic Editor, click <Access database or Access project name> Project Properties on the Tools menu.
  2. On the Protection tab, select the Lock project for viewing check box. If you set a password but don't select Lock project for viewing, the code can be viewed and edited by anyone, but the Project Properties dialog box is protected.
  3. In the Password box, type your password.

ShowGuidelines for passwords

Use strong passwords that combine uppercase and lowercase letters, numbers, and symbols. Weak passwords don't mix these elements. Strong password: Y6dh!et5. Weak password: House27. Passwords should be 8 or more characters in length. A pass phrase that uses 14 or more characters is better. For more information, see Help protect your personal information with strong passwords.

It is critical that you remember your password. If you forget your password, Microsoft cannot retrieve it. Store the passwords that you write down in a secure place away from the information that they help protect.

User names can range from 1 to 20 characters, and can include alphabetic characters, accented characters, numbers, spaces, and symbols, with the following exceptions:

  • The characters " \ [ ] : | < > + = ; , . ? *
  • Leading spaces
  • Control characters (ASCII 10 through ASCII 31)

 Note   Passwords are case-sensitive (case-sensitive: Capable of distinguishing between uppercase and lowercase letters. A case-sensitive search finds only text that is an exact match of uppercase and lowercase letters.).

  1. In the Confirm password box, confirm your password by typing the password again, and then click OK.

The password is now set. The next time you or any other user opens the database, a dialog box will be displayed that requests a password.

 Important   If you forget your password, it can't be recovered, and you won't be able to view or edit the VBA code.

ShowCreate an MDE file


  1. If your database enabled user-level security (user-level security: When using user-level security in an Access database, a database administrator or an object's owner can grant individual users or groups of users specific permissions to tables, queries, forms, reports, and macros.), you must meet certain requirements before you can save it as an MDE file.

Requirements for saving a file with user-level security as an MDE file

  1. Close the Microsoft Access database. If you are working in a multiuser environment, make sure that all other users have closed the Access database.
  2. On the Tools menu, click Database Utilities, and then click Make MDE File.
  3. In the Database To Save As MDE dialog box, specify the Access database you want to save as an MDE file, and click Make MDE.
  4. In the Save MDE As dialog box, specify a name, drive, and folder for the Access database.
Applies to:
Access 2003