Sizing an Access report, opened as acDialog while the main window is hidden (1 Viewer)

PleasantB

Registered User
Joined
Dec 12, 2018
Messages
26
I already asked this question on Stack Overflow but received no responses.
I just came across this forum so thought I might have better luck here.

I am utilizing forms and reports from an old Access database in a C# application.
I do this by launching the Access database, hiding the main window, and calling a procedure that opens the form or report in a separate window.

I achieve a separate window by opening the form or report with acDialog.
A popup form also resulted a separate window but a popup report did not.

The forms are working great but I cannot get the reports to show unless I execute DoCmd.Maximize in Report_Open.

Maximizing causes the report to take up the entire screen, which is not ideal.
I wish to set the report to a size of my choosing but both the built-in Access command DoCmd.MoveSize and Windows API SetWindowPos cause the report to rejoin the main Access window, which is hidden.

I'm hoping someone can suggest a way to achieve my goal.

C# code:

Code:
    class Program
    {
        private static readonly string DbLocation = "C:\\example.accdb";

        [DllImport("user32.dll")]
        private static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
        private const int KeyDownEvent = 0x0000;
        private const int KeyUpEvent = 0x0002;

        static void Main(string[] args)
        {
            ProcessStartInfo startInfo = new ProcessStartInfo()
            {
                FileName = GetOfficeAppPath("Access.Application", "msaccess.exe"),
                Arguments = DbLocation,
                WindowStyle = ProcessWindowStyle.Hidden
            };

            // Simulate holding the Shift key, while opening the application, to bypass startup proceedings.
            keybd_event((byte)Keys.LShiftKey, 0, KeyDownEvent, 0);
            Process process = Process.Start(startInfo);
            process.WaitForInputIdle();
            keybd_event((byte)Keys.LShiftKey, 0, KeyUpEvent, 0);

            Access.Application exampleApp = (Access.Application)Marshal.BindToMoniker(DbLocation);

            try
            {
                exampleApp.Run("OpenReport", 12345);
            }
            catch (Exception e)
            {
                MessageBox.Show($"{e.Message}\n{e.InnerException?.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                exampleApp.CloseCurrentDatabase();
                process.Kill();
            }
        }
    }
 

PleasantB

Registered User
Joined
Dec 12, 2018
Messages
26
I tried that originally but found that though a popup form is not hidden with the main Access window, a popup report is.
The only way I found to have a report persist when the main Access window is hidden is opening the report with WindowMode set to acDialog.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top