【发布时间】:2012-03-13 13:47:37
【问题描述】:
我有一个个人数据库应用程序,最初是使用 Access 2007 中的 mdb 格式设计的。出于安全原因,我已将其转换为 .accdb。除了更改数据库密码功能外,所有功能都转换得很好。此功能在 VBA 中完成,因为 Db 已关闭所有工具栏。在 mdb 格式中......这很好用
DBPath = [CurrentProject].[FullName]
' 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
我在这个论坛上发现了一些与 .accdb 接近的东西,但它只适用于另一个 .accdb 文件,而不适用于当前项目......
strAlterPassword = "ALTER DATABASE PASSWORD [" & NwPswd& "] [" & 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] <- this does not work: get a file already in use error
.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
那么有没有办法在 VBA 中为 .accdb 文件执行此操作?基本上它将自动化第一次解密的工具栏功能并使用新密码进行加密。我知道工具栏可以做到,所以我知道必须有 VBA 方法来做到这一点。
【问题讨论】:
-
由于这可能是一次性的,您能否在您的专属副本中重新打开工具栏并通过应用程序修改密码?
标签: ms-access ms-access-2007 connection-string