Check whether a form is loaded

Check whether a form is loaded

You can load several instances of the same form, but VB doesn’t let you determine how many forms of a given class are currently loaded. You can work around this flaw by iterating over the Forms collection:

' Return the number of instances of a form' that are currently loadedFunction FormCount(ByVal frmName As String) As Long    Dim frm As Form    For Each frm In Forms        If StrComp(frm.Name, frmName, vbTextCompare) = 0 Then            FormCount = FormCount + 1        End If    NextEnd Function

You can use the previous routine to determine whether any instance of a form is loaded, as in:

If FormCount("form1") > 0 Then    ' Form1 is already loadedEnd If


Share the Post: