Hiding MS-Access background application from a dat

2019-07-26 10:08发布

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条回答
Lonely孤独者°
2楼-- · 2019-07-26 10:23

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.

查看更多
登录 后发表回答