最小化MS Access窗口离开POPUP表单

时间:2015-02-26 06:32:10

标签: vba ms-access access-vba ms-access-2010

我有以下代码来最小化MS访问,但弹出窗体会随后台消失......

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

有没有人知道如何离开弹出窗体并最小化访问背景?

2 个答案:

答案 0 :(得分:1)

我知道这样做的唯一方法是将call fSetAccessWindow(SW_SHOWMINIMIZED)放在form_load事件中。这对我来说是可靠的

答案 1 :(得分:0)

诀窍是之后使用Form.SetFocus cmd。由于主屏幕最小化SetFocus cmd之后将保持形式:

Private Sub cmdMinimize_Click()
        Call fSetAccessWindow(SW_SHOWMINIMIZED)
        Form.SetFocus
End Sub