试试我这个函数吧,我一直都这样用,没有出现过问题。
Function ComDB()
On Error GoTo err_ComDB
Dim mydb, strPath As String
Dim wenjian
Set wenjian = CreateObject("scripting.filesystemobject")
Set mydb = CurrentDb
strPath = Left(mydb.Name, Len(mydb.Name) - 9)
DBEngine.CompactDatabase strPath & "BusDown.mdb", strPath & "temp.mdb"
Kill strPath & "BusDown.mdb"
Name strPath & "temp.mdb" As strPath & "BusDown.mdb"
Exit Function
err_ComDB:
MsgBox Err.Description
ComDB = CVErr(65534)
End Function