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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Do I Compact Database With an Event Procedure?

Status
Not open for further replies.

Bill6868

Technical User
Mar 20, 2007
96
0
0
US
Is there a simple code to attach to an event procedure to compact a database? I'd like to have the db compact and repair when I click the Exit command button on my form.

Some of the threads I've read are really difficult for my level of programming.

Thanks for any suggestions.

bill6868
 
LaurieHamlin,

I'm using Access 2007.

Thanks,

Bill
 
I use Office 2010 and found this command
DoCmd.RunCommand acCmdCompactDatabase

But doesn't look like this can be ran from a form button or macro.

Error: You cannot compact the open database by running a macro or Visual Basic code.

Matt
 
I got this working on my database.

VBA code:

'Compact and close the Access Database
DoCmd.CloseDatabase
DoCmd.RunCommand acCmdCompactDatabase
 
Mhouser83 said:
I got this working on my database.

'Compact and close the Access Database
DoCmd.CloseDatabase
DoCmd.RunCommand acCmdCompactDatabase
If you're going to do that why not simply check the 'Compact on Close' on the Current Database Options?

The problem with all of these is that Compacting a Database has been frequently cited as a cause of corruption, and therefor should not be done without first making a backup copy of the file!


The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top