• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 38
  • Last Modified:

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.
0
Clive Beaton
Asked:
Clive Beaton
  • 2
1 Solution
 
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 ArchitectCommented:
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
 
Clive BeatonAccess DeveloperAuthor Commented:
Thanks, Joe.  Looks like just what I need.

Clive
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
You are welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now