Private Sub Command1_Click()
On Error GoTo Err_Handle
Dim dbE As New DAO.DBEngine
dbE.CompactDatabase "C:\要压缩的.mdb", "B:\压缩后的.mdb"
Exit Sub
Err_Handle:
MsgBox Err.Description
Exit Sub
End Sub
2.用jet引擎压缩数据库
工程-引入 Microsoft Jet and Replication Objects Library
Private Sub Command1_Click()
Dim FIXDB As New JRO.JetEngine
FIXDB.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:aa.mdb", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:aac.mdb"
End Sub
3.引用ACCESS压缩数据库
設定引用項目 Microsoft Access X.X Object Library
Dim objAcc As New Access.Application
或
Dim objAcc As Object
Set objAcc = CreateObject("Access.Application")
之後
Call objAcc.CompactRepair("c:\要压缩的.mdb", "C:\压缩后的", False)