2
我有一個最初在Access 2007中使用mdb格式設計的個人數據庫應用程序。出於安全原因,我已將其轉換爲.accdb。除了更改DB密碼功能外,所有功能均可正常轉換。此功能在VBA中完成,因爲Db已將所有工具欄關閉。在MDB格式...這工作正常是否可以使用VBA來更改當前的accdb/e數據庫密碼
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文件做到這一點?基本上它會自動執行第一個Decrypt的工具欄功能,並用新密碼進行加密。我知道工具欄可以這樣做,我知道必須有一種VBA的方式來做到這一點。
由於這可能是一次性關閉,您是否可以不通過應用程序將專用工具欄重新打開並修改密碼? – 2012-02-23 09:26:33