2012-02-23 68 views
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的方式来做到这一点。

+1

由于这可能是一次性关闭,您是否可以不通过应用程序将专用工具栏重新打开并修改密码? – 2012-02-23 09:26:33

回答

0

我发现了这个问题的解决方案,或者只是一个解决方法。通过删除ADO库,第一种方法将适用于.Accde格式的文件。它不适用于.accdb格式文件,但您不想分发这些文件。

相关问题