Discussion Locked

Access 97 - Compact database ?

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have written some VBA code (in Access 97) that compacts a given database.
The format is :
dbengine.compact
I do not want to create another copy of the db, but compact it onto itself, but the source and destination files cannot be the same.
The TOOLS->DATABSE UTILITIES->COMPACT menu option works great, but I want to automate the process, pergaps on shut down of the db.

Can anyone give me some pointers on how to gain access to this menu option, via code? or some better way of compacting my DB ?

Many thanks, in Advance, for your help
Mark.

6 replies

by peyison

Mark,

I think you're on the right track. What I would recommend is adding some code to your VBA routine that,upon completion of the compact function, would delete the source db and rename the destination to the original name. One good thing aboutthis method is that if for some reason the compact function doesn't complete successfully (e.g. user shuts down before it's done), you haven't lost your original database.

Hope this helps.

by mbutton

Michael,
Thanks for the input.
The dbengine.compact does not return an error code. How do I know if it completed successfully, or not?

Also - I really wanted to put this code into the 'on unload' event of the form. that way, whenever a user closes the DB, the code will run automatically. Your suggested solution needs the source DB to be closed (so that I can overwrite it).
Thanks again for your input. If I cant get any more info - this is the solution I will use.

by nicholasp

I fought with this exact problem a couple of years ago, and found the only way was to choose the options from the menu. Unfortunalty Microsofts wisdom did not think we would want to compact databases. Ofcourse now you could use Access 2000......

This discussion is closed to new replies.