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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Sepop

New Member
Joined
Jun 30, 2014
Messages
22
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

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,836
Office Version
  1. 2019
Platform
  1. Windows
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

AOB

Well-known Member
Joined
Dec 15, 2010
Messages
638
Office Version
  1. 365
  2. 2016
  3. 2013
Platform
  1. Windows
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,191,171
Messages
5,985,067
Members
439,938
Latest member
MAlhash

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
Top