Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automating Compact & Repair Routine

Status
Not open for further replies.

missymarie1014

Technical User
Mar 15, 2007
50
US
I have an Access 2000 application that I have written that is completely menu driven. Users have no access to the typical menu bars or context menus. I am wondering if there is a way to automatically run the Tools|DatabaseUtilities|CompactAndRepairDatabase routine when the user exits the software or when the user opens the software. Can you reference this routine through code somehow and make it happen?
Or, in lieu of this and to avoid potential problems if multiple users are accessing the program, is there a way to automate that process to run at a particular time, say after the store is closed and the software is definitely not being used?
Thanks in advance for any help and ideas!
 
You cannot execute code to compact a database from itself.
You can either check the option to "Compact on Close", or create an exe or mde that compacts from Windows Scheduler (or an open app with a timer). The VBA would look something like
Code:
DBEngine.CompactDatabase DBName, NewDBName

"Don't be irreplaceable. If you can't be replaced, you can't be promoted."
 
Thanks for the respopnse genomon! I see the checkbox for CompactOnClose and that will serve my needs I believe. It works fine. However another question came to mind. If the database is being used by 2 people concurrently, does it wait for the final user to exit before compacting, and, if not, would the compact on close option be a potential problem with respect to data integrity if data is being written at the same time that the first user has exited and the database might be compacting?
 

Also, it's a really good idea to copy your file before doing a C & R. Compacting can actually cause data corruption.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top