从动态打开的数据库隐藏MS-Access后台应用程序 [英] Hiding MS-Access background application from a database opened dynamically
问题描述
我使用以下代码从我的主应用程序中隐藏背景MS-Access窗口。
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
我如何使这个工作从主应用程序?我想我也可以在 myDatabasePath 数据库中的 myFormName 形式调用我的fSetAccessWindow()函数,但我想从主应用程序调用第二个 mdb 文件。
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.
我使用Access 2007开发Access 2000-2003 MDB数据库。
I'm using Access 2007 to develop Access 2000-2003 MDB databases.
推荐答案
使用 Application.hWndAccessApp方法检索第二个Access应用程序实例的窗口句柄。
Use the Application.hWndAccessApp Method to retrieve the window handle of the second Access application instance.
appAccess.hWndAccessApp
将该值馈送到 apiShowWindow()
函数。
我没有测试这个,所以不确定是否忽略了一些东西,但这似乎是一个合理的起点。
I didn't test this, so unsure whether I overlooked something, but it seems like a reasonable starting point to me.
这篇关于从动态打开的数据库隐藏MS-Access后台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!