Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to check if a form is loaded?

Posted on 2004-08-24
5
Medium Priority
?
1,200 Views
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.
0
Comment
Question by:mlcktmguy
5 Comments
 
LVL 11

Expert Comment

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

MyForm.Show
0
 
LVL 3

Accepted Solution

by:
nichia earned 200 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
Next

Hope it helps!
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 11882707
Or


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
            Forms(i).SetFocus
            Exit Function
        End If
    Next
End Function

Dim FrmD As form1
If (IsLoaded("form1") = False) Then
        Set FrmD = New form1
        FrmD.Show
    End If
0
 
LVL 1

Author Comment

by:mlcktmguy
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.
0
 

Expert Comment

by:superile
ID: 25915840
Is there a method to check if a form is loaded in vb.net?
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

824 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