1) Private Function CreateDBPassword(ByVal Password As String, _
ByVal Path As String) As Boolean
Dim objConn as ADODB.Connection
Dim strAlterPassword as String
On Error GoTo CreateDBPassword_Err
' Create the SQL string to initialize a database password.
strAlterPassword = "ALTER DATABASE PASSWORD [Password] NULL;"
' Open the unsecured database.
Set objConn = New ADODB.Connection
With objConn
.Mode = adModeShareExclusive
.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data " & _
"Source=Path;"
' Execute the SQL statement to secure the database.
.Execute (strAlterPassword)
End With
' Clean up objects.
objConn.Close
Set objConn = Nothing
' Return true if successful.
CreateDBPassword = True
CreateDBPassword_Err:
Msgbox Err.Number & ":" & Err.Description
CreateDBPassword = False
End Function
2) 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 [NewPassword]
[OldPassword];"
' 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=Path;"
' 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
Regards,
Zuzar.L.
"Jassim Rahma" <jra...@hotmail.com> wrote in message
news:13f7101c29418$8feaa240$8df82ecf@TK2MSFTNGXA02...
> how can I check if and mdb password is password protected
> or not? I need to write a code to check if the the mdb
> file was not password, then setup a password for it.
Unless you know the MDB password, you cannot change it. So, essentially, a
password protected MDB will throw an exception when attempted to open using
an incorrect password (you can use this to check if its password protected).
That said, if you know the password, you can change it. Have a look at this
link which exemplifies the same using SQL:
http://www.dbmaker.com.tw/reference/manuals/sql/commands/alterpassword.html
--
Kumar Gaurav Khanna
*************************************************************************
"I can't be Garbage Collected... I am pinned to .NET"
WinToolZone @ http://www.wintoolzone.com/
eXPerience.NET @ http://www.experiencedotnet.com/
"Jassim Rahma" <jra...@hotmail.com> wrote in message
news:13f7101c29418$8feaa240$8df82ecf@TK2MSFTNGXA02...
> how can I check if and mdb password is password protected
> or not? I need to write a code to check if the the mdb
> file was not password, then setup a password for it.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.422 / Virus Database: 237 - Release Date: 20-Nov-2002