【问题标题】:Is it possible to use VBA to change the Current accdb/e Database password是否可以使用 VBA 更改当前 accdb/e 数据库密码
【发布时间】: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


【解决方案1】:

我找到了解决此问题的方法,或者可能只是一种解决方法。通过删除 ADO 库,第一种方法将适用于 .Accde 格式的文件。它不适用于 .accdb 格式文件,但无论如何您都不想分发这些文件。

【讨论】:

    猜你喜欢
    • 2015-10-26
    • 1970-01-01
    • 2015-12-20
    • 2017-01-29
    • 2011-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多