Need to Compact and Repair from VBA code

Sepop

New Member
Joined
Jun 30, 2014
Messages
22
Hi,

I have a VBA code that deletes some old data from my database and uploads the new data into it from some excel files.

The thing is that the macro stops in the middle and brings me the error that the database reached it maximum capacity but when I click the Compact and Repair button the DB goes from 2GB to 600MB.

Is there a code to run the Compact and Repair command in the middle of the code?

Thanks!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Some clarifications:

I am the only user of the database and I need this code to run in the middle of another code...
 
Upvote 0
Your code could not run in the database itself, since you lose the execution during the compact and repair. You'd have to code this to automate the DB from another DB. Then you can:

1) Delete old data
2) compact and repair
3) now import new data

Simplest to achieve this is to set the compact and repair on close option, which simplifies the procedure to:
1) delete old data
2) close database
3) reopen database
4) import new data
 
Upvote 0
xenou,

If the DB was split, you could perform the C&R from the FE? I have written code to do this, although it is a bit clunky as you have to remove the linked tables first (effectively cutting off the BE), then C&R the BE as normal, then relink the tables.

Just saying... :)
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,734
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top