devxlogo

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

See also  Essential Measures for Safeguarding Your Digital Data
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist