Results 1 to 5 of 5

Thread: [RESOLVED] Check if Form2 is loaded WITHOUT loading it

  1. #1

    Thread Starter
    Addicted Member cc2^^'s Avatar
    Join Date
    Apr 2008
    Location
    Right behind you.
    Posts
    165

    Resolved [RESOLVED] Check if Form2 is loaded WITHOUT loading it

    I know there is an easy way to do this, to check if a form is loaded without loading it. Because when i try
    If Form2.visible = True Then
    then it loads the form.
    I think I am, therefore, I am. I think.

  2. #2
    gibra
    Guest

    Re: Check if Form2 is loaded WITHOUT loading it

    Try this

    Code:
    If Form2 Is Nothing Then
       Load Form2
    End If

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [RESOLVED] Check if Form2 is loaded WITHOUT loading it

    If Form2 exists, it will never be nothing.

    There are a couple ways to do this
    1. When Form2 loads, have it set a public variable either in your main form or in a bas module & reset it when it unloads
    2. Add this to your Form2
    Code:
    Public isLoaded As Boolean
    
    Private Sub Form_Load()
        isLoaded = True
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
        isLoaded = False
    End Sub
    
    ' Now from any code, you can check via:  Form2.isLoaded = True
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: [RESOLVED] Check if Form2 is loaded WITHOUT loading it

    Use the forms collection to check
    Code:
    Private Sub Command1_Click()
    Dim frm As Form
    Dim blnLoaded As Boolean
    
        For Each frm In Forms
            If frm.Name = "Form2" Then
                blnLoaded = True
            End If
        Next frm
        
        MsgBox "Form2 is loaded = " & blnLoaded
    End Sub
    
    Private Sub Command2_Click()
        Load Form2
    End Sub

  5. #5
    gibra
    Guest

    Re: [RESOLVED] Check if Form2 is loaded WITHOUT loading it

    Quote Originally Posted by LaVolpe View Post
    If Form2 exists, it will never be nothing.
    It's true!
    I'm a chicken

    Sorry...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width