Try the module below... you can set the size that you want the database to compact at.. I have added an extra msgbox to allow the user to decide.
Public Function AutoCompactCurrentProject()
Dim fs, f, s, filespec
Dim strProjectPath As String
Dim strProjectName As String
strProjectPath =...