I want a cmd button on a form that lets the user "compact and Repair" the database.
The menu's have been removed.
There is a hidden menu, called "Developer" which is only accessible thru a password protected form, that has the menu option "Compact and Repair Database..."
Here's what I have: (in a module)
Public Sub CompactDB()
Commandbars("Developer").Controls("Compact and Repair Database...").accDoDefaultAction
The menubar is labeled Developer and Compactandrepairdatabase is listed in the first pull down
I've been trying the same for ages, and never got it to work.
Sorry to say...
It is possible to compact and repair from code, but than from within a second database: DBEngine.CompactDatabase Name1, Name2
You cannot compact a database that you are working in from within itself, as far as I know.
It is possible to use the menu-button Access provides in itself, that works like a charm.
However there I believe you have to distinguish between your Database and the running Access-application.
Using the Access-menu bar for compact and repair, your Access-application first closes your database, than compacts (including possible file renaming) your database and than re-opens your database.
So you may understand that your database cannot close itself, than compact itself, renames and re-opens again.
is get the database to open another application (i.e. another database) and then close.
The other application should:
this database should have a form that open automatically. This form should have a timer event set to (say) 10 secs. This timer event should opent the database you want to compact with the /compact /repair startup options. Then close.
could you be a little more specific please. what i gather is:
DB1 is open with a form that has a cmd button that "compacts"
then on the on click event:
DB2 opens with hidden form that
DB2 then closes
is it something like that or am I completely lost?