数据库压缩
各位大虾,小第有个问题想请教下Function CompactDB(dbPath, boolIs97)
Dim fso, Engine, strdbpath
strdbpath = left(dbPath,instrrev(dbpath,"\"))
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(dbPath) Then
Set Engine = CreateObject("JRO.JetEngine")
If boolIs97 = "True" Then
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath, _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb;" _
& "Jet OLEDB:Engine Type=" & JET_3X
Else
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath, _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb"在这里程序报错尝试打开的数据库已经被机器 'SJOU2007' 上的用户 'Admin' 以排它的方式打开。当数据库可使用后请再试一次。
End If
fso.CopyFile strDBPath & "temp.mdb",dbpath
fso.DeleteFile(strDBPath & "temp.mdb")
Set fso = nothing
Set Engine = nothing
CompactDB = "您所指定的数据库, " & dbpath & ", 已经被压缩" & vbCrLf
Else
CompactDB = "您所输入的数据库路径或名称未找到,请重试" & vbCrLf
End If
End Function