Is it possible to change the backend database password from the front end in VBA

I had this question after viewing Problem word extracting data from an Access database.
Clive BeatonAccess DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pawan KumarDatabase ExpertCommented:
The best is to call a stored procedure from UI code and then pass the password to the sp and sp  will take care of it.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Yes it is possible. Here is the VBA code to change the Database Password in an Access database (ie in a back end)

   Public Function SSF_PwdCtl() As Boolean
    'CurrentDb.NewPassword "MyNewPassword", "MyOldPassword"

' all code from experts exchange
    'Dim WS As DAO.Workspace
    Dim sDbName As String
    Dim sPwdOld As String
    Dim sPwdNew As String
    Dim db As DAO.Database

    sDbName = "C:\SomeFolder\SomeDatabase.mdb"
    sPwdOld = InputBox("Old Pwd: ")
    sPwdNew = InputBox("New Pwd:")
    'sPwdOld = "***"
    'sPwdNew = "SomeNewPassword"   ' or ""
   
    Set db = DBEngine.Workspaces(0).OpenDatabase(sDbName, options:=True, readonly:=False, Connect:=";PWD=" & sPwdOld & ";")
   
    db.NewPassword sPwdOld, sPwdNew
   
    MsgBox "Pwd Accepted"
    Set db = Nothing
    SSF_PwdCtl = True

End Function

Note that using the Input Box is of course optional. You can certainly hard code the Old and New
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Clive BeatonAccess DeveloperAuthor Commented:
Thanks, Joe.  Looks like just what I need.

Clive
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
You are welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.