Hello:
This is my first post so please be gentle. :) I spend 99.9% of my development in a
VB .NET/C# .NET/ASP .NET/etc.. environment so this is relatively "new" to me. I have a bit of VBA experience from college but that's about it. I need to get my learning curve on. :)
I have a VBA 2007 application that has several different forms including a Switchboard type page. I'd like to have this page be visible (Opened?) if the user closes the other forms. I created a Functions modules that iterates through Form's collection and checks if a form is open. But, I'd rather not put a function call to this in every single form's Close event. Is there a global event or a better way to do this? Thanks in advance.
Here's the code for anyone that cares:
' Checks if the specified form is open
Public Function IsFormOpen(ByVal sFormName As String) As Boolean
' Validation
If (IsNull(sFormName) = True Or Len(sFormName) = 0) Then Exit Function
' Check if specified form is open
If SysCmd(acSysCmdGetObjectState, acForm, sFormName) = acObjStateOpen Then
If Forms(sFormName).CurrentView = 1 Then
IsFormOpen = True
Else
IsFormOpen = False
End If
End If
End Function
' Check if any form is open
Public Function IsAFormOpen() As Boolean
' Local Variables
Dim iCounter As Integer ' Counter
Dim bReturn As Boolean ' Is a form open flag (RETURN)
' Initialize
iCounter = 0
bReturn = False
' Validation
If (Forms Is Null) Then Exit Function
' Check if a form is open
For iCounter = 0 To Forms.Count - 1 Step 1
If (Functions.IsFormOpen(Forms(iCounter).Name) = True) Then
bReturn = True
Exit For
End If
Next iCounter
' Return
IsAFormOpen = bReturn
End Function