Make your own free website on Tripod.com
Set A Password For An Access Database

This code will show you how to set a password for an access database
that currently doesn't have password.

Preparations

Add reference to DAO:
from the menu choose Project-> References, mark the Microsoft DAO 3.6 (or 3.51) Object Library check box, and press OK.

Add 1 Command Button to your form.
Press the button to set a new password to the database.

Form Code

Public Sub SetDatabasePassword(DBFile As String, Password As String)
    Dim db As Database
    ' open the database
    Set db = OpenDatabase(DBFile, True)
    ' set the new password 
   
db.newPassword "", Password
    ' close the database
    db.Close
End Sub

Private Sub Command1_Click()
    Call SetDatabasePassword("c:\YourDir\DataBaseFileName.mdb", "TheNewPassword")
End Sub

Go Back