1

我正在使用以下代码从我的主应用程序中隐藏后台 MS-Access 窗口。

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

但是,我想对使用以下代码打开的另一个数据库(表单)执行相同的操作:

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

我怎样才能从主应用程序中完成这项工作?我想我也可以从myDatabasePath数据库中的myFormName表单调用我的 fSetAccessWindow() 函数,但我想从调用第二个mdb文件的主应用程序中调用。

我正在使用 Access 2007 开发 Access 2000-2003 MDB 数据库。

4

1 回答 1

1

使用Application.hWndAccessApp 方法检索第二个 Access 应用程序实例的窗口句柄。

appAccess.hWndAccessApp

将该值提供给apiShowWindow()函数。

我没有对此进行测试,因此不确定我是否忽略了某些东西,但这对我来说似乎是一个合理的起点。

于 2013-01-04T17:41:04.083 回答