MSAccess最小化主数据库窗口,打开模态弹出窗体

时间:2017-11-21 06:56:24

标签: ms-access minimize ms-access-2016

启动* .accdb时,会打开并最大化模式弹出窗体。当表单最小化时,可以在后台看到主DB窗口:

enter image description here

当模式弹出窗体最小化时,是否可以最小化主DB窗口,以便它根本不显示主DB窗口。

我已经尝试过以下代码。但是,它会抛出一个错误,说“#34;无法最小化访问XXX表单在屏幕上"。

有人可以帮忙吗?

更新:如果我将表单设置为模态:否,它可以正常工作。主DB窗口最小化到任务栏。但是,如果我单击任务栏中的图标,它将再次打开弹出窗体,并在后台显示主数据库窗口。是否可以将主数据库窗口最小化到通知区域?

Option Compare Database 
Option Explicit 

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

这是On Load事件。

Private Sub Form_Load()
    Call fSetAccessWindow(SW_SHOWMINIMIZED)
End Sub

1 个答案:

答案 0 :(得分:0)

在加载事件

上使用此功能
cusID