I'm pretty sure there is no way to intercept the Compact and repair command
in the menu. Instead you need to take a different approach to this. Setup a
custom toolbar with a custom button or a command button on an administration
form. When the user clicks the button run your if statement in the button
click event and then run the compact and repair.
This link should take you to the MSDN article on compacting the database
with ADO.
http://support.microsoft.com/default.aspx?scid=kb;en-us;230501
If it doesn't search on the following "ado compact database".
To prevent your users from going around your if statement hide all toolbars
and menus. You can do this in Tools and then Startup.
~Mark