I don't use a macro, but this might work for you:
Create a command button on a form. I use the Main Switchboard in one
database and a Add/Edit form in another. Using the On Click event of the
command button:
Private Sub Command172_Click()
On Error GoTo ProcError
CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Database utilities"). _
Controls("Compact and repair database..."). _
accDoDefaultAction
ExitProc:
Exit Sub
ProcError:
MsgBox "error" & Err.Number & ": " & Err.Description
Resume ExitProc
End Sub
This usually works fine, but because there is one form open, the database
does not compact as much as when the form is closed. Not a lot of difference,
though.