how to make only one ohbject of a form at a time in vb,net

I am wokring on a project and in that I have two forms.
One is mdi parent form and second is the child of first form.
So when I open the second through first form using menus.
I want that if the second form is alrady open then a message shuld come that says like the form is already open.

So how to do it
In samiple words I want only insatance of second form at a particular time.
And the seond instance should make when the firt one is distroed.

And also I have this code and I want to know whcih class should I import in my class to use this code below

dim app as SQLDMO.Application
app = new SQLDMO.ApplicationClass
dim names as SQLDMO.NameList
names = app.ListAvailableSQLServers()
dim i%
for i = 1 to names.Count
   cboServers.Items.Add names.Item(i)

Who is Participating?
Alexandre SimõesManager / Technology SpecialistCommented:

For the first question, just use the following code before you actually create the form you want to show:

            For Each f As System.Windows.Forms.Form In Me.MdiChildren
                If TypeOf f Is myForms.Form1 Then
                    System.Windows.Forms.MessageBox.Show("Form already open")
                    Exit Sub
                End If
            '*** Place your form creation code here ***

where myForms.Form1 is the form you want to show.
This will prompt you a messagebox informing that an instance of that form is already open and will exit the sub, skiping the creation code.

----- // -----

For the SQLDMO problem...

Go to your project references, Add a new COM Reference : Microsoft SQLDMO Object Library

That's all...

Alex :p

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.