Excel to repair Access database

adder

New Member
Joined
Apr 21, 2009
Messages
12
Not sure whether I should post this in the Access section, but here's what I need - creat a macro in excel to compact 2 Access dbs (Risk.mdb and Riskdata.mdb)

This is a daily task for me, for now I'm doing it mannually, open each database, and go Tools --> database utilities --> compact and repair database.

I've thought about using macro within each database - whenever opening the file it triggers repair automatically, however I don't want to do it every time I open the database, instead I wish to control the repair from a master excel file.

Thanks for your help in advance
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Can't you just set both databases to compact and repair on close?
 
Upvote 0
This was discussed fairly recently - 1-2 months ago, perhaps - and I seem to recall we came to the conclusion that you couldn't trigger a compact & repair from Excel.

Try doing a forum search.
 
Upvote 0
Thanks all you guys above. I decided to go with scheduled tasks. It's probably easier.
 
Upvote 0
Why not File>Options and select Compact on close in the Current Database section?

PS That's for 2010, but the option is available in other versions.
 
Upvote 0
Hi Norie,

I should've stated it clearer... I use 2003 version of Excel and Acess. I was too lazy to manually open the 2 mdb just for the sake of compact and repair (c/r), and then manually close them. So either c/r on open or on close is not something I was looking for.

Initially I thought if hitting a button in a excel file would automatically open the 2 access mdb, do the c/r, then close mdb - that would be ideal.

For now I'm settled with the scheduled task, which automatically opens 1 mdb at a time, does c/r, and closes the mdb, at a specified time every day. I also created the task shortcuts on desktop so that if I need to c/r at any other time I can double click the shortcuts to do the job automatically.

Having said that, I'll continue to search an one-button-click solution from Excel. Thanks
 
Upvote 0
This appears to work in Excel 2007:-
Code:
Sub CRDB()
 
    Dim oAcc As Access.Application

    Set oAcc = CreateObject("Access.Application")

    oAcc.DBEngine.CompactDatabase "c:\temp\test1.mdb", "c:\temp\test2.mdb"
 
End Sub
You need a reference to the Microsoft Access Object Library. You end up with the new database in a different file but I guess you can KILL the old file and NAME the new one back.

I can't test in Excel 2003.
 
Upvote 0
Why do you need to compact and repair a database that hasn't been used recently?

If you do want code that opens, compacts and repairs then closes why not set the database to compact and repair on close?

Then all you need is code that will open and close the database.

The compact and repair will happen automatically when the code closes the database.
 
Upvote 0
I agree with Norie. The setting he is talking about is one of those "Set it and forget it" settings. It may add a few extra seconds to closing time.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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