Could someone help me with this one?

I have developed a small application. It has a MDIParent form on which the other childforms are displayed. I have a Panel on the MDIParent on which there are buttons to call up the MDIChild forms. Now my issue is, when anyone of the buttons on the MDIParents form Panel are clicked, it should check if another Childform is display, if it is then it (the active childform is closed) and the new form will be displayed. This part is working fine from the code below. However, when there are no active MDIChild form on the MDIParent form and if the button is clicked, the 'Else' part of my code below is executed. This generates the error as 'Object reference not set to an instance of an object'. So what is wrong with my code below? Please help me get this one done. :confused:

Thanking you in advance..

Private Sub btnExecutive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExecutive.Click
        Dim MDIChildForm As New frmExecutiveInfo
        MDIChildForm.MdiParent = Me
            If MDIChildForm.MdiParent.ActiveMdiChild.Visible = True Then
            End If
        Catch ex As Exception
        End Try
    End Sub

Edited 5 Years Ago by kipslem: n/a

The else part is not getting reached when there is no mdi child. Instead your starting the if off with .ActiveMdiChild.visible = true.

If there is no .ActiveMdiChild then your checking the visiblity of a form that doesn't exist. That were the object reference not set to an instance is coming from.

Use this instead:

If Me.ActiveMdiChild Is Nothing Then
    'show your new form
    'show your new form
 End If

Thanks Unhnd_Exception for the help.

It's working fine after your help.

Thanks once again.

This question has already been answered. Start a new discussion instead.