Solved

How to check if a form is loaded?

Posted on 2004-08-24
5
1,194 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 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
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

685 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