2017-02-21 157 views
0

我有一個訪問數據庫,在窗體背後有一些表單和vba代碼。Form_Open VBA代碼不能正常工作

Form_Open(在每個表單上)我有這段代碼。

Dim hWindow As Long 
Dim nResult As Long 
Dim nCmdShow As Long 

    hWindow = Application.hWndAccessApp 
    nCmdShow = SW_HIDE 
    nResult = ShowWindow(ByVal hWindow, ByVal nCmdShow) 
    Call ShowWindow(Me.hWnd, SW_NORMAL) 

這隱藏了Access並僅顯示打開的窗體。

我的問題是Access正在啓動,但表單無法打開。

我必須殺死任務管理器中的Access任務。

有什麼辦法可以解決這個問題嗎?

編輯:每個表單是一個彈出

回答

2

據我瞭解,你需要隱藏的主要形式,並留下彈出的形式開放。我通常使用窗口不透明度設置,而不是隱藏:

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long 
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long 
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long 

Private Const LWA_ALPHA  As Long = &H2& 
Private Const LWA_COLORKEY As Long = &H1& 
Private Const GWL_EXSTYLE As Long = -20 
Private Const WS_EX_LAYERED As Long = &H80000 

Public Function SetWndOpacity(hwnd As Long, opacity As Byte, clr As Long) 
    DoCmd.Maximize 
    SetWindowLong hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED 
    SetLayeredWindowAttributes hwnd, 0&, opacity, LWA_ALPHA 
End Function 

然後調用:

SetWndOpacity Access.hWndAccessApp(), 0, 0