I think that may be correct. (I am no expert...)
I have an admin screen that has a button that compacts and repairs the
back-end of the database. This is my code (below). It tells the user
that everything will close, etc.
--------------------------------------------------------------------------------------------------
Private Sub cmdCompact_Click()
Dim DB As String
DB = """" & DLookup("[FileLocation]", "tbl_FileLocations",
"[Name]='Database'") & """"
Repsonse = MsgBox("Compacting and Reparing the Database will close
any open screens, run the Compact and Repair procedure and then exit
the Database. You will also be asked for the Database password." &
vbCrLf & vbCrLf & "Do you wish to continue?", vbYesNo + vbQuestion,
"Compact and Repair")
If Repsonse = vbNo Then Exit Sub
Do While Forms.Count > 0
DoCmd.Close acForm, Forms(0).Name, acSavePrompt
Loop
Do While Reports.Count > 0
DoCmd.Close acReport, Reports(0), acSavePrompt
Loop
MsgBox "This process may take several minutes. Do not close any
Microsoft Access windows during the Compact and Repair procedure.",
vbExclamation, "Warning"
Shell "msaccess.exe. " & DB & " /repair", vbNormalFocus
DoCmd.Quit acQuitPrompt
End Sub
Again, I am no expert but this works quite well in my opinion...