Hi All,
I have a little Access app DB that has an option to let the user assign a new password to the database. In the .mbd or .mde format the option worked fine. But when I switched to the .accdb format the change password option failed with the error message the the file was already locked by another process.
The original code
allows the user to change the password on the current DB even though it is open. If the file was a .MDb or .MDE
I tried the below code for the ADO version for the .accdb or .accde format
With this code the process still errors out this time however I keep getting file already in use error.
I have a little Access app DB that has an option to let the user assign a new password to the database. In the .mbd or .mde format the option worked fine. But when I switched to the .accdb format the change password option failed with the error message the the file was already locked by another process.
The original code
Code:
DBPath = [CurrentProject].[FullName]
Dim dbsDB As DAO.Database
Dim strOpenPwd As String
' Create connection string by using current password.
strOpenPwd = ";pwd=" & 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
I tried the below code for the ADO version for the .accdb or .accde format
Code:
Dim ADO_Cnnct As adodb.Connection, strAlterPassword As String
strAlterPassword = "ALTER DATABASE PASSWORD [" & Pswd2 & "] [" & OldPswd & "];"
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]
.Open "Data Source= " & DBPath & ";"
' Execute the SQL statement to change the password.
.Execute (strAlterPassword)
End With
'Clean up objects.
ADO_Cnnct.Close
Set ADO_Cnnct = Nothing
Last edited: