Compact Database using JRO (Jet & Replication objects)
I recently developed a database application and wanted to use only ADO and no DAO. I soon found out that compacting the Jet database was impossible using ADO (until 2.1+ came along that is). This code requires a reference to Microsoft Jet and Replication objects 2.1+ Library (which comes with ADO 2.1+). You can download this update from http://www.microsoft.com/data.
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
'## To use:
private sub command1_click()
msgbox compressdatabase ("C:\database.mdb") '## Replace with path to database
end sub
Public Function CompressDatabase(mSourceDB As String) As Boolean
on error goto Err
Dim JRO As JRO.JetEngine
Set JRO = New JRO.JetEngine
Dim srcDB As String
Dim destDB As String
srcDB = mSource
destDB = "backup.mdb"
JRO.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & srcDB & ";Jet OLEDB:Database Password=" & PASSWORD, _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & destDB & ";Jet OLEDB:Database Password=" & PASSWORD & ";Jet OLEDB:Engine Type=4"
Kill srcDB
DoEvents
Name destDB As srcDB
compressdatabase = true
exit function
Err:
compressdatabase = false
End Function
Original Comments (3)
Recovered from Wayback Machine