1

I'm using the following code to hide the background MS-Access window from my main application.

Global Const SW_HIDE = 0
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Global Const SW_SHOWMAXIMIZED = 3
Private Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Function fSetAccessWindow(nCmdShow As Long)
    Dim loX As Long
    Dim loForm As Form
    On Error Resume Next
    Set loForm = Screen.ActiveForm

    If Err <> 0 Then
        loX = apiShowWindow(hWndAccessApp, nCmdShow)
        Err.Clear
    End If

    If nCmdShow = SW_SHOWMINIMIZED And loForm.Modal = True Then
        MsgBox "Cannot minimize Access with " _
        & (loForm.Caption + " ") _
        & "form on screen"
    ElseIf nCmdShow = SW_HIDE And loForm.PopUp <> True Then
        MsgBox "Cannot hide Access with " _
        & (loForm.Caption + " ") _
        & "form on screen"
    Else
        loX = apiShowWindow(hWndAccessApp, nCmdShow)
    End If
    fSetAccessWindow = (loX <> 0)
End Function

However, I would like to do the same with another database (form) that I'm opening with the following code:

Dim appAccess As Access.Application
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase "myDatabasePath"
appAccess.DoCmd.OpenForm "myFormName"
Set appAccess = Nothing

How could I make this work from the main application? I guess I could also call my fSetAccessWindow() function from the myFormName form in myDatabasePath database but I would like to do it from the main application that calls that second mdb file.

I'm using Access 2007 to develop Access 2000-2003 MDB databases.

1 Answer 1

1

Use the Application.hWndAccessApp Method to retrieve the window handle of the second Access application instance.

appAccess.hWndAccessApp

Feed that value to the apiShowWindow() function.

I didn't test this, so unsure whether I overlooked something, but it seems like a reasonable starting point to me.

Sign up to request clarification or add additional context in comments.

1 Comment

It just perfectly works, I should have figured this out myself before. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.