Compact and Repair Database via Macro

  • Thread starter Thread starter Akua Aning
  • Start date Start date
A

Akua Aning

Hello Everyone!

I wanted to know if it is possible to compact and repair a
database using a macro (as opposed to manually doing it).
I tried running the following macro:

Action: RunCommand
Command: CompactDatabase

but I received the following error: You can't compact the
open database while running a macro or Visual Basic code.

Is there another way to automate this process?

Thanks for your help!
Akua Aning
(e-mail address removed)
 
You cannot compact a database using a macro or code. You
can have the application compact everytime you exit it.
In the tools/option menu in the general tab there is
a "Compact on close" check box.

Eric
 
You can do this in code after a fashion. It is possible to set the
option 'Compact on Close' in code. So on close you make your decision
about whether compacting is needed or was selected and set the option
accordingly. E.g.
If FileLen(CurrentDb.Name) > MAX_APPSIZE Then
MsgBox "The Application file is too bigger it will be compacted"
SetOption "Auto Compact", True
Else
' Does not need compacting yet
SetOption "Auto Compact", False
End If

BTW - if you come across it, SetOption "Auto Compact Percentage" does
not work.
 
Hi!

Did you ever get a resolution to this problem? I just
posted this same question to the Microsoft site today...
We are wanting to do this same function... Please let me
know the details of any solution you discovered...

Thanx! m
 
Back
Top