Securing and Sharing Information in Microsoft Office Access 2007

  • 1/3/2007

Preventing Changes to Database Code

If you have added Microsoft Visual Basic for Applications (VBA) procedures to a database, you certainly don’t want users who aren’t qualified or authorized to make changes to your code. You can prevent unauthorized access in two ways: by protecting your VBA code with a password, or by saving the database as a Microsoft Database Executable (ACCDE) file. If you set a password for the code, it remains available for editing by anyone who knows the password. If you save the database as an ACCDE file, people using the database application can run your code, but they can’t view or edit it.

In this exercise, you will secure the VBA code in a database by assigning a password to it.

  1. On the Database Tools tab, in the Macro group, click the Visual Basic button.

    httpatomoreillycomsourcemspimages1122348.jpg

    The Visual Basic Editor starts.

    httpatomoreillycomsourcemspimages1122350.jpg
  2. On the Tools menu, click base Properties.

    The Project Properties dialog box opens.

  3. On the Protection tab, select the Lock project for viewing check box.

  4. In the Password box, type 2007!VbA, and then press the httpatomoreillycomsourcemspimages1121704.jpg key.

    httpatomoreillycomsourcemspimages1122352.png

    Access disguises the characters of the password as asterisks as you type them, to protect against other people seeing your password.

  5. In the Confirm Password box, type 2007!VbA, and then click OK.

    The password is set, but you won’t have to enter it again until the next time you open the database and attempt to edit the VBA code.

  6. Close the Visual Basic Editor, and then close the database.

  7. Reopen the database, and then on the Database Tools tab, in the Macro group, click the Visual Basic button (or press httpatomoreillycomsourcemspimages1121712.png).

    The Visual Basic Editor opens, displaying only the name of the project, and not the Code window.

    httpatomoreillycomsourcemspimages1122354.jpg
  8. Click the Expand button to the left of the Prevent database project.

    httpatomoreillycomsourcemspimages1121748.png

    Expand

    The Password dialog box opens.

  9. In the Password dialog box, type 2007!VbA, and then click OK.

    The project expands to display its components.