Make your own free website on Tripod.com
Change An Access Database Password

This code will show you how to change an access database password from Visual Basic using code.

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 change the database password.

If you got "Unrecognized Database format" error message:

If you using database that made in Access 2000 and you don't have Microsoft DAO 3.6 Object Library reference, click on browse, and select the file C:\Program Files\Common Files\Microsoft Shared\Dao\dao360.dll (If you have Access 2000 installed in your computer you have this file.)
This will add Microsoft DAO 3.6 Object Library reference to your project. Now mark it and press OK.

Form Code

Private Sub ChangeAccessPassword(OldPass As String, NewPass As String)
    Dim Db As Database
    ' opens the databse, using the old password.
    ' replace "C:\MyDir\Mydb1.mdb" with your database file name

    Set Db = OpenDatabase("C:\MyDir\Mydb1.mdb", True, False, ";pwd=" & OldPass)
    ' setthe new password
   
Db.NewPassword OldPass, NewPass
    ' close the database
    Db.Close
End Sub


Private Sub Command1_Click()
' replace "oldPassword" with the current database password, and
' "newPassword" with the new password you want the database will have.
   
Call ChangeAccessPassword("oldPassword", "newPassword")
End Sub

Go Back