Results 1 to 3 of 3

Thread: Active form

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Gloucestershire, England
    Posts
    301

    Post

    How can I tell if a form is active from a function?

    What I want to do is have a check box menu item to open/close a window. But I need a way to tell if its open so I know to close it and not open it (if you see what I mean!)

    Thanks in advance

  2. #2
    Guest

    Post

    If you have a form called Form1 and it is not loaded, if you write :

    Unload Form1

    No error is generated. If Form1 is loaded, it will unload.

    So, go ahead and load & unload the forms according to your program's needs.

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    You can check the Forms Collection for a Certain Form, if it's there, then it's been loaded, otherwise it hasn't, ie.
    Code:
    Private Sub Command1_Click()
        If IsLoaded("Form2") Then MsgBox "Form2 Is Already Loaded"
    End Sub
    
    Private Function IsLoaded(ByVal sFormName As String) As Boolean
        For Each Form In Forms
            If LCase(Form.Name) = LCase(sFormName) Then
                IsLoaded = True
                Exit For
            End If
        Next
    End Function

    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    ajyoung@pressenter.com


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