PDA

View Full Version : using VBA to change the password on an .accdb or accde



msowards
02-15-2012, 02:44 PM
I have a little Access app originally written using .mdb /.mde. It has an option to change the currently assigned password. When I converted to a .accdb format to take advantage of the higher security levels. This option no longer works. The old version ....


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


...works fine

but this new version causes...


Dim ADO_Cnnct As adodb.Connection, strAlterPassword As String

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
ADO_Cnnct.Close
Set ADO_Cnnct = Nothing

... causes file already inuse message
I'v tried different modes but still get the error message.

Is there a way to change the DB password when using the accdb or accde file format?

mohanvijay
02-16-2012, 01:20 AM
try .Properties("ACE instead of .Properties("Jet

msowards
02-16-2012, 02:13 PM
I changed 'Jet' to 'ACE' and got: Run-Time error 3265 -- "Item cannot be found in the collection corresponding to the requested name or ordinal".
I'm :banghead:

mohanvijay
02-19-2012, 04:26 AM
Try connection string as follow


"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=yourdatasorce;Jet OLEDB:Database Password=youroldpassword;Mode=Share Deny Read|Share Deny Write;"


query to change password



qry="ALTER DATABASE PASSWORD new password old password"