Dim retval As Variant retval = MsgBox("This command will log you off and compact your database. Do you wish to continue?", vbOKCancel) Debug.Print retval If retval = 2 Then MsgBox "action cancelled" GoTo getout End If DoCmd.ShowToolbar "bmMenuBar", acToolbarYes DoCmd.Close acForm, "MainMenu" CommandBars("Menu Bar"). _ Controls("Tools"). _ Controls("Database utilities"). _ Controls("Compact and repair database..."). _ accDoDefaultAction getout: