我有 MS Access DB,其中包含多种表单。与主菜单类似的主窗体是“F_StartUp”,其中包括几个用于激活其他窗体的按钮。当我打开表单时,“F_StartUp”最小化。我需要一个 VBA 来检查何时关闭所有表单,如果所有表单都关闭,则最大化/打开“F_StartUp”。以下是我到目前为止所拥有的:
Option Explicit
Sub openstartup()
Dim frm As Object
Dim isF_InPutOpen As Boolean
Dim isF_CarriersOpen As Boolean
Dim isF_InvOpen As Boolean
Dim isF_QuoteOpen As Boolean
' Initialize variables to False
isF_InPutOpen = False
isF_CarriersOpen = False
isF_InvOpen = False
isF_QuoteOpen = False
For Each frm In CurrentProject.AllForms
If frm.IsLoaded Then
If frm.Name = "F_InPut" Then
isF_InPutOpen = True
ElseIf frm.Name = "F_Carriers" Then
isF_CarriersOpen = True
ElseIf frm.Name = "F_Inv" Then
isF_InvOpen = True
ElseIf frm.Name = "F_Quote" Then
isF_QuoteOpen = True
End If
End If
Next frm
' Check the status of each form
If isF_InPutOpen Then
' Code to be executed when F_InPut is open
End If
If isF_CarriersOpen Then
' Code to be executed when F_Carriers is open
End If
If isF_InvOpen Then
' Code to be executed when F_Inv is open
End If
'
If isF_InvOpen Then
' Code to be executed when F_Quote is open
End If
'This will call macro module which will open 'F_StartUp'
Call "workeddddd"
End Sub
Application.Forms
集合包含所有开放表格。
If Application.Forms.Count = 1 Then
If Application.Forms(0).Name = "F_StartUp" Then
DoCmd.Maximize ' Or DoCmd.Restore
End If
End If
也许第一个
If
就足够了,如果主窗体是唯一可以单独打开的:
If Application.Forms.Count = 1 Then
DoCmd.Maximize ' Or DoCmd.Restore
End If