Update to MDAC 2.6 and Jet 4.0. The following does work...
Private Sub mnuRepairDatabase_Click()
Dim fso As New FileSystemObject, File1 As File
Dim je As New JRO.JetEngine
'Set objDB = Nothing 'only used if the database is opened from a class module
' Make sure that a file doesn't exist with the name of
' the compacted database.
If Dir(App.Path & "\Sys\MyDB2.mdb"

<> "" Then
Kill App.Path & "\Sys\MyDB2.mdb"
End If
On Error GoTo errorhandler
' Compacts and encrypts version MyDB database.
je.CompactDatabase _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= " & App.Path & "\Sys\MyDB.mdb", _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= " & App.Path & "\Sys\MyDB2.mdb;" & _
"Jet OLEDB:Encrypt Database=True"
If Dir(App.Path & "\Sys\MyDB2.mdb"

<> "" Then
Kill App.Path & "\Sys\MyDB.mdb"
Set File1 = fso.GetFile(App.Path & "\Sys\MyDB2.mdb"

File1.Copy App.Path & "\Sys\MyDB.mdb"
End If
MsgBox "Database Repair Complete"
Exit Sub
errorhandler:
If Err = -2147467259 Then
'Err.Description
MsgBox "Error# " & Err & " -> " & Err.Description
End If
End Sub
If the database is open by another user, the error will occur
Good Luck