'安装Microsoft ActiveX Data Objects 2.X library (X为1以上) '引用Microsoft Jet and Replication Objects 2.X library Dim jro As jro.JetEngine Set jro = New jro.JetEngine jro.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\test\test.mdb", _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\test\new.mdb;"
Sub CompactDatabaseX() Dim dbsNorthwind As Database Set dbsNorthwind = OpenDatabase("Northwind.mdb") ' Show the properties of the original database. With dbsNorthwind Debug.Print .Name & ", version " & .Version Debug.Print " CollatingOrder = " & .CollatingOrder .Close End With ' Make sure there isn't already a file with the ' name of the compacted database. If Dir("NwindKorean.mdb") <> "" Then _ Kill "NwindKorean.mdb" ' This statement creates a compact version of the ' Northwind database that uses a Korean language ' collating order. DBEngine.CompactDatabase "Northwind.mdb", _ "NwindKorean.mdb", dbLangKorean Set dbsNorthwind = OpenDatabase("NwindKorean.mdb") ' Show the properties of the compacted database. With dbsNorthwind Debug.Print .Name & ", version " & .Version Debug.Print " CollatingOrder = " & .CollatingOrder .Close End WithEnd Sub
'引用Microsoft Jet and Replication Objects 2.X library
Dim jro As jro.JetEngine
Set jro = New jro.JetEngine
jro.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\test\test.mdb", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\test\new.mdb;"
With dbsNorthwind
Debug.Print .Name & ", version " & .Version
Debug.Print " CollatingOrder = " & .CollatingOrder
.Close
End With ' Make sure there isn't already a file with the
' name of the compacted database.
If Dir("NwindKorean.mdb") <> "" Then _
Kill "NwindKorean.mdb" ' This statement creates a compact version of the
' Northwind database that uses a Korean language
' collating order.
DBEngine.CompactDatabase "Northwind.mdb", _
"NwindKorean.mdb", dbLangKorean Set dbsNorthwind = OpenDatabase("NwindKorean.mdb") ' Show the properties of the compacted database.
With dbsNorthwind
Debug.Print .Name & ", version " & .Version
Debug.Print " CollatingOrder = " & .CollatingOrder
.Close
End WithEnd Sub