Home > Enterprise >  Compacting Access files quietly
Compacting Access files quietly

Time:10-09

I created a script that compacts .mdb files on a schedule.

It works great when I call msaccess.exe with the /compact argument, except when it finds an mdb file that has been corrupted.

Instead of compacting it, it stops processing and shows this message until I click OK, and only after that does it start the compacting: microsoft access has detected that this database is in an inconsistent state

How do I avoid this window? Is there a /quiet or /nogui equivalent argument that shows no GUI and just does the compact commmand?

This script would run at night and I can't be there to click OK every time.

JETCOMPACT is not an option, because it freezes when I try to compact one of our mdb files.

CodePudding user response:

There isn't an easy way in terms of a /quiet command switch but various options are described here:

https://answers.microsoft.com/en-us/msoffice/forum/all/is-there-a-way-to-do-a-quiet-command-line-ms/fe22a76e-3e45-4716-884c-1641ef75d3cf

CodePudding user response:

I solved it myself in PowerShell. This compacts and repairs mdb files without confirmation or messageboxes interrupting:

$ObjectAccess = New-Object -ComObject "Access.Application"
$ObjectAccess.CompactRepair($MDBFilePathSource, $MDBFilePathDestination)
$ObjectAccess.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($ObjectAccess)
  • Related