Question : Force close an .mdb file that is in use then compact and repair it using vba code

Is it possible to force close an .mdb file that is in use then compact and repair it using vba code

Answer : Force close an .mdb file that is in use then compact and repair it using vba code

I use the following routine in a form that looks up a 'CloseCount' and 'CompactFrequency' from a settings table. If the close count exceeds the compact frequency then it will compact the datbase when it closes and reset the 'CloseCount'  to 1

Have a look at the attached demo file.

To compact on close on demand use the following code

Private Sub cmdCompactNow_Click()
        Application.SetOption "Auto Compact", True
        DoCmd.Quit
End Sub

reset the Auto Compact to false when the DB opens


Private Sub Form_Open(Cancel As Integer)
    Application.SetOption "Auto Compact", False
End Sub

Hope that helps and answers the question.


 
 
Compact on close and on demand
 
Random Solutions  
 
programming4us programming4us