tags:

views:

96

answers:

3

How can I know that the form (other than the one I'm working upon) is open or closed?

+3  A: 

You can search the Forms collection

Dim aForm
For Each aForm In Forms
  If aForm Is Form1 Then
    MsgBox "Found Form1"
  End If
Next
Jan Willem B
+1  A: 

If the form is in your application, you can simply track its state internally. After all-- you control the points in code when it can be created or destroyed.

Greg D
+7  A: 

You have to distinguish between Loaded and Visible.

  • For visiblility just check the Visible property (noting that doing so for an unloaded form will cause it to become loaded).
  • For the loading state unfortunately there is no property. You have to iterate over all forms, and look whether your form is contained in the list of loaded forms:

    Public Function IsFormLoaded(FormToCheck As Form) As Boolean
      Dim F As Form 
      For Each F In Forms
        If F Is FormToCheck Then
          IsFormLoaded = True
          Exit Sub
        End If
      Next
    End Sub
    

The global collection Forms contains all currently loaded forms.

DR