Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to check if a form is loaded?

Posted on 2004-08-24
5
Medium Priority
?
1,198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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

719 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