How to check if a form is loaded?

Posted on 2004-08-24
Last Modified: 2012-05-05
My user has requested to be able to get anywhere from anywhere in the application.  I have buttons on the forms that provide this ablity.  How can I check if a form is loaded?  If a form is already loaded I don't want to re-load it.
Question by:mlcktmguy
LVL 11

Expert Comment

ID: 11882168
You can just use the .Show method - this will load the form if it is not already loaded.


Accepted Solution

nichia earned 50 total points
ID: 11882199
Calling for example Load Form2 will not cause the form to reload if it has already been loaded.  The Form_Load sub is called only when the form is either called the first time, or first unloaded, then called again.

If you still need to determine what forms are in memory, you can iterate the Forms collection:

Dim frm As Form
For Each frm In Forms
    If frm.Name = "Form2" Then
        Debug.Print "Form2 is Loaded"
    End If

Hope it helps!
LVL 26

Expert Comment

ID: 11882707

Public Function IsLoaded(ByVal FormName As String) As Boolean
    Dim i As Integer

    On Error Resume Next
    IsLoaded = False
    For i = 0 To Forms.Count - 1
        If Forms(i).Name = FormName Then
            IsLoaded = True
            Exit Function
        End If
End Function

Dim FrmD As form1
If (IsLoaded("form1") = False) Then
        Set FrmD = New form1
    End If

Author Comment

ID: 11882972
Thank you nichia and EDDYKT both of your solutions look like they work.  I was implementing the solution provide by nichia when EDDYKT responded.  The nichia solution does work and it was provided first so I am awarding the points to nichia.

Expert Comment

ID: 25915840
Is there a method to check if a form is loaded in

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now