Function CreateNormalDB(strPathName As String) As Boolean
On Error GoTo Exit_ERR
Dim wrkDefault As Workspace
Dim NewDB As Database
CreateNormalDB = False
Set wrkDefault = DBEngine.Workspaces(0)
If Dir(strPathName) <> "" Then Kill strPathName
Set NewDB = wrkDefault.CreateDatabase(strPathName, dbLangGeneral)
NewDB.Close
Set NewDB = Nothing
CreateNormalDB = True
Exit Function
On Error GoTo Exit_ERR
Dim wrkDefault As Workspace
Dim NewDB As Database
CreateNormalDB = False
Set wrkDefault = DBEngine.Workspaces(0)
If Dir(strPathName) <> "" Then Kill strPathName
Set NewDB = wrkDefault.CreateDatabase(strPathName, dbLangGeneral)
NewDB.Close
Set NewDB = Nothing
CreateNormalDB = True
Exit Function
Exit_ERR:
MsgBox "备份失败!" & vbCrLf & vbCrLf & Err.Description, vbExclamation
Exit Function
End Function
'调用时只需提供路径及文件名即可,此函数为备份数据模块的一部份
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-122900/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10294527/viewspace-122900/
本文介绍了一个VBA函数,用于在指定路径下创建一个空白的Access数据库。该函数首先检查目标路径是否存在,如果存在则删除原有文件,然后创建新的数据库,并确保在创建过程中出现错误时能够给出提示。
630

被折叠的 条评论
为什么被折叠?



