您现在的位置: 万盛学电脑网 >> 程序编程 >> 数据库 >> access教程 >> access基础教程 >> 正文

创建一个带密码的空数据库

作者:佚名    责任编辑:admin    更新时间:2022-06-22

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
Exit Function
End Function