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

Microsoft Office Access 2003

To prevent someone from viewing or making changes to your Microsoft Visual Basic for Applications (VBA) code, you can help protect the code by requiring a password.

  1. Open the Microsoft Access project (.adp) file or Microsoft Access database (.mdb) 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.

    ShowTip

    You can also press ALT+F11.
  3. In the Microsoft Visual Basic Editor, click <Access database or Access project name> Project Properties on the Tools menu.
  4. 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.
  5. In the Password box, type your password.

    ShowGuidelines for passwords

    Use strong passwords that combine upper- and lowercase letters, numbers, and symbols. Weak passwords don't mix these elements. Strong password: Y6dh!et5. Weak password: House27. Use a strong password that you can remember so that you don't have to write it down.

    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.

  6. 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

Caution

  • Be sure to save a copy of your original Microsoft Access database in a secure location. You can't modify the design of forms, reports, or modules in an Access database saved as an MDE file. If you need to change the design of these objects, you must do so in the original Access database and then resave the Access database as an MDE file.
  • You can't create an MDE file in Microsoft Access 2002 or later from a database created in an earlier version. You can only save an MDE file from a database of the same version of Access.
  • You also won't be able to convert an Access database saved as an MDE file in later versions of Access. You can run the MDE file in a later version of Access.
  1. If your database enabled user-level security, 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

    • You must join the workgroup information file that defines the user accounts used to access the database, or that were in use when the database was created.
    • Your user account must have Open/Run and Open Exclusive permissions for the database.
    • Your user account must have Modify Design or Administer permissions for any tables in the database, or you must be the owner of any tables in the database.
    • Your user account must have Read Design permissions for all objects in the database.
  2. Close the Microsoft Access database. If you are working in a multiuser environment, make sure that all other users have closed the Access database.
  3. On the Tools menu, click Database Utilities, and then click Make MDE File.
  4. 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.
  5. In the Save MDE As dialog box, specify a name, drive, and folder for the Access database.