萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 資料庫 >> Access 教學 >> Access 基礎教學

VBA 創建帶密碼的空 Access 資料庫函數代碼

Function CreatePasswordDB(strPathName As String, strPsd As String) As Boolean
    On Error GoTo Exit_ERR
    Dim wrkDefault As Workspace
    Dim NewDB As Database

    CreatePasswordDB = False
    Set wrkDefault = DBEngine.Workspaces(0)
    If Dir(strPathName) <> "" Then Kill strPathName
    Set NewDB = wrkDefault.CreateDatabase(strPathName, dbLangGeneral & ";pwd=" & strPsd & "")

    NewDB.Close
    Set NewDB = Nothing
    CreatePasswordDB = True
    Exit Function

Exit_ERR:
    MsgBox "備份失敗!" & vbCrLf & vbCrLf & Err.Description, vbExclamation
    CreatePasswordDB = False
End Function

調用示例:CreatePasswordDB "C:\Data\NewDB.mdb", "123456",成功返回 True,失敗彈窗提示錯誤詳情。

copyright © 萬盛學電腦網 all rights reserved