0

I'm compacting a lot of MDB files on the command line by scripting with msaccess.exe, e.g.:

> msaccess.exe example.mdb /compact

When this runs, the Access UI appears for a moment. I'd like to prevent the UI from appearing at all.

I'm using Access 2013, in case it might matter.

I've searched for an exhaustive command line parameter reference and only found this MS Support KB article among several similar pages, all with essentially the same info and none mentioning any version of Access newer than 2003.

Of the parameters listed at the above-linked article, I tried /nostartup and /runtime, but neither did the trick.

How can the Access UI be suppressed when running msaccess.exe on the command line?

William
  • 1,993
  • 2
  • 23
  • 40
  • Did some research, you can "suppress" the splash screen itself by placing a 1x1 pixel .bmp file named the same as your Access file (db.mdb would be db.bmp) which it will bring up in lieu of the normal Access splash. However, the UI seems to always make brief appearance in my testing. There isn't a command line way to suppress that, I don't think. Maybe have this on start up on your db?: http://www.tek-tips.com/faqs.cfm?fid=2562 – VBlades Jun 24 '14 at 02:34
  • @VBlades, thanks for the tip. It would be difficult for me to insert VBA into every DB I'm operating on, so I don't think I would take that approach. Some msaccess.exe command parameter or other global-ish mechanism would be ideal. Still, thanks. – William Jun 24 '14 at 15:58
  • This question is [being discussed on Meta](http://meta.stackoverflow.com/questions/261716). – Robert Harvey Jun 26 '14 at 20:27
  • 2
    Do you have any interested in taking a different approach? Instead of using the `msaccess.exe` command line arg, you could [write a quick and dirty script to compact the db](http://stackoverflow.com/a/3133849/656243). – Lynn Crumbling Jun 26 '14 at 20:35
  • @LynnCrumbling, thanks, and I'd definitely be interested in different approaches. A central script like that could work, but I'll have to study up on Access/VBA. (I originally hoped to stay away from the Access/VBA learning curve, however small, but this may be for the best.) I'll post an answer here when I take the time to figure it out unless somebody beats me to it. In the meantime, I've made myself content with the entrancing, desktop-monopolizing effect of flashing Access windows `;-)` – William Jun 26 '14 at 22:26

1 Answers1

1

With the .NET Framework, setting ProcessStartInfo.WindowStyle to ProcessWindowStyle.Hidden does the trick.

Here's a simple class I wrote to encapsulate what I want. It also incorporates the splash image trick mentioned in the comments to this question (another source), since I couldn't find any other way to actually eliminate the splash image.

public class MsaccessCompactor
{
    const string DefaultPathToMsaccess =
        @"C:\Program Files\Microsoft Office\Office15\MSACCESS.EXE";

    static readonly Bitmap BlackPixel;

    static MsaccessCompactor()
    {
        BlackPixel = new Bitmap(1, 1);
        BlackPixel.SetPixel(0, 0, Color.Black);
    }

    readonly string PathToMsaccess;

    public MsaccessCompactor(string pathToMsaccess = DefaultPathToMsaccess)
    {
        PathToMsaccess = pathToMsaccess;
    }

    public void Compact(string pathToDatabase)
    {
        var arguments = string.Format("\"{0}\" /compact", pathToDatabase);
        var startInfo = new ProcessStartInfo(PathToMsaccess, arguments);
        startInfo.WindowStyle = ProcessWindowStyle.Hidden;

        var pathToBmp = Path.ChangeExtension(pathToDatabase, "bmp");
        BlackPixel.Save(pathToBmp, ImageFormat.Bmp);

        using (var process = Process.Start(startInfo))
        {
            process.WaitForExit();
        }

        File.Delete(pathToBmp);
    }
}

Note that there will still be a very short focus-defocus due to the seemingly unavoidable splash image appearance. Fortunately, it doesn't seem to markedly affect desktop usability in my very brief, very informal, self-performed acceptance testing. (And most thankfully, there is no Access UI window at all. Yay!)

William
  • 1,993
  • 2
  • 23
  • 40
  • If C# is an option, I do have code that compacts a database using only library routines, and not the full `MSAccess.exe` process. Should I post it as an answer? – Lynn Crumbling Oct 30 '14 at 20:16