title: Is it possible to use VBA to change the Current accdb/e Database password
body: <p>I have a personal DB app that was initially designed using the mdb format in Access 2007.  For security reasons I've converted it to .accdb.  All functions converted fine except the change DB password function.  This function is done in VBA because the  Db has all the tool bars turned off.   In mdb format... this works fine </p>
  
  <pre><code>DBPath = [CurrentProject].[FullName]
  
  ' Create connection string by using current password.
  strOpenPwd = ";pwd=" &amp; OldPswd
  
  ' Open database for exclusive access by using current password. To get
  ' exclusive access, you must set the Options argument to True.
  Set dbsDB = OpenDatabase(Name:=DBPath, _
                           Options:=True, _
                           ReadOnly:=False, _
                           Connect:=strOpenPwd)
  
  ' Set or change password.
  With dbsDB
      .NewPassword OldPswd, Pswd2
      .Close
  End With
  
  Me.DB_Pswd = Pswd2
  
  Set dbsDB = Nothing
  </code></pre>
  
  <p>I found something from this very forum that comes close for the .accdb  but it only works for another .accdb file not the current project....</p>
  
  <pre><code>strAlterPassword = "ALTER DATABASE PASSWORD [" &amp; NwPswd&amp; "] [" &amp; OldPswd &amp; "];"
  
  Set ADO_Cnnct = New adodb.Connection
  With ADO_Cnnct
      .Mode = adModeShareExclusive
  
      .Provider = "Microsoft.ACE.OLEDB.12.0"
      '  Use old password to establish connection
      .Properties("Jet OLEDB:Database Password") = OldPswd
  
      'name  current DB
  
      DBPath = [CurrentProject].[FullName]  &lt;- this does not work: get a file already in use error
  
      .Open "Data Source= " &amp; DBPath &amp; ";"
      ' Execute the SQL statement to change the password.
      .Execute (strAlterPassword)
  End With
  
  'Clean up objects.
  ADO_Cnnct.Close
  Set ADO_Cnnct = Nothing
  </code></pre>
  
  <p>So is there a way to do this in VBA for .accdb files?  Basically it would be automating the tool bar function of first Decrypt and the encrypt with a new password.  I know the tool bar can do so I know there must be a VBA way to do it.  </p>