JroCompactADO




'## Requires reference to Microsoft Jet and

'Replication objects 2.1+ Library (Standard ADO 2.1+ feature)

Public Const PASSWORD = "password"
'replace With database password

'Returns:True or False depending on success of operation

Set the current connection To nothing before compacting (set mcn = nothing).
'## 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

Assumes:
I use this routine in the form_unload sub to compact the
current database. If you were to try to compact while
there was still an active connection, Jet locking would
take over and return an error.










( jrocompactado.html )- by Paolo Puglisi - Modifica del 17/12/2023