I'm trying to change a password for a .mde file programatically. I used the code provided by Mircosoft but it doesn't work and always gives me an error message that "Sub or Function not defined". Here is the link for reference:
http://msdn.microsoft.com/en-us/libr...urity_password
Here is the code:
Code:
Private Function ChangeDBPassword(ByVal OldPassword As String, _
ByVal NewPassword As String, ByVal Path As String) As Boolean
Dim objConn as ADODB.Connection
Dim strAlterPassword as String
On Error GoTo ChangeDBPassword_Err
' Create the SQL string to change the database password.
strAlterPassword = "ALTER DATABASE PASSWORD [123] [abc];"
' Open the secured database.
Set objConn = New ADODB.Connection
With objConn
.Mode = adModeShareExclusive
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Jet OLEDB:Database Password") = "OldPassword"
.Open "Data Source=[c:\data\db1.mde];"
' Execute the SQL statement to change the password.
.Execute (strAlterPassword)
End With
' Clean up objects.
objConn.Close
Set objConn = Nothing
ChangeDBPassword = True
ChangeDBPassword_Err:
Msgbox Err.Number & ":" & Err.Description
ChangeDBPassword = False
End Function