Hi Guys!

I just need a little help on how to detect if a form is open or loaded.? When it is loaded or open, i want it to show or visible when a button is click..

Something like this...

if frmisOpen(frmname)=true then
   'show or load the form
end if

Thank you & God bless us.!

Recommended Answers

All 7 Replies

Use the instance method of the object(form) to check one instance is already running..

Sorry there is no such method called instance.
We need to write custome code to check.

Private Shared _Instance As Form1 = Nothing

    Public Shared Function Instance() As Boolean
        If _Instance Is Nothing OrElse _Instance.IsDisposed = True Then
            _Instance = New Form1
            Return False
        End If
        _Instance.BringToFront()
        Return True
    End Function

Try this

the simple way :)

Private Sub Command1_Click()
If Form2.Visible = True Then
'form is loaded
MsgBox ("Form 2 is loaded")
Else
MsgBox ("Form not loaded")
End If
End Sub

You can do that first by adding a public flag[do that in a module so you can access it anywhere], when form is loaded change it's value to 1. In button click if flag =1 then the form is loaded .

Private Sub Command1_Click()
If Flag = 1 Then
'form is loaded
MsgBox ("Form 2 is loaded")
Else
MsgBox ("Form not loaded")
End If
End Sub
Private Sub Command2_Click()
Form2.Show
End Sub

Change Flag when form2 closes

Private Sub Form_Load()
Flag = 1
End Sub
Private Sub Form_Unload(Cancel As Integer)
Flag = 0
End Sub

@Vineeth

If a form is not visible (hidden), that does not mean the form is not loaded.

thank you guys for the answers..Any way, both solutions just solved it..just a combination of setting the flag and form instances..

Thank You!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.