I also couldn't find a way to compact an Access database while the database was open. However, I do have code that will compact an Access database from a
VB application that is using the Access database for data. I don't know if it will help anyone or not. I didn't write this code. It was in an application that I inherited and now have to support.
Private Sub CompressB_Click()
If MsgBox("Run compress now?", vbYesNo) = vbYes Then
Screen.MousePointer = vbHourglass
On Error Resume Next
Kill gsDBPath + "stoppay2.mdb"
On Error GoTo 0
DBEngine.CompactDatabase gsDBPath + "stoppay.mdb", gsDBPath + "stoppay2.mdb"
Kill gsDBPath + "stoppay.mdb"
Name gsDBPath + "stoppay2.mdb" As gsDBPath + "stoppay.mdb"
Screen.MousePointer = vbDefault
MsgBox "Compress is complete."
End If
End Sub