It is only opening it once as you close the existing form!
Let us look at the code and see what it does - i will comment existing code:
#Region "Forms"
' create a variable for holding a generic form. since the
' code only uses the "Import" form i would have made this
' Public ImportForm As Import
' but there really is no need.
Public ImportForm As Form
#End Region
.
.
Private Sub LinkLabel2_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
Try
' if there is an existing instance of the form
' referenced by "ImportForm" then close it. This
' is why you beleive that the code only allows you
' to open one instance. in fact it does open the new
' instance after first closing the existing instance.
ImportForm.Close()
' general cleanup of variables.
ImportForm = Nothing
' create a reference to a new "Import" form and assign
' the reference to our variable
ImportForm = New Import()
' general parent setting. Though this is setting the
' parent as the parent of the calling form?! Not
' knowing the entire code, i am not sure if this is
' the case.
ImportForm.MdiParent = Me.MdiParent
' show the form that is referenced by our "ImportForm"
' variable
ImportForm.Show()
Catch ex As Exception
' The catch ignores all errors and doesn't care
' what it was. in fact the first time through this code
' this code will be executed after the code attempts
' to close a form referenced by our varaiable that does
' not reference a form!
' this creates a reference to the form
ImportForm = New Import()
' sets the parent
ImportForm.MdiParent = Me.MdiParent
' shows the form
ImportForm.Show()
Finally
' no finally code
End Try
End Sub
A suggested implementation would be as follows:
Public ImportForm As Import
Private Sub LinkLabel2_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
Try
' we do not want to close the existing form referenced
' by the "ImportForm" variable.
' create a reference to a new "Import" form and assign
' the reference to our variable
ImportForm = New Import()
' general parent setting, this should allow us to get to
' the form created via the parent-child relationship,
' rather than the ImportForm variable
' I called this code from my actual parent, so the
' reference is me.
ImportForm.MdiParent = Me
' show the form that is referenced by our "ImportForm"
' variable
ImportForm.Show()
Catch ex As Exception
' The catch ignores all errors and doesn't care
' what it was. but we should know while developing!
' so we might be able to avert poor coding
MsgBox(ex.Message, MsgBoxStyle.Critical, ex.Source)
Finally
' we no longer need to reference the created child form
' via our variable, in fact we should not! this child
' may close without us catching the close. plus, we
' would then need to keep all references in an array.
' but shice the mdiparent provides this control auto-
' matically, we will reference it in that fashion.
' clean up the variable
ImportForm = Nothing
' let us see how many children the mdiparent has! you
' can close the children and this value is correct for
' the count of actual live children.
Debug.WriteLine("Children=" + Me.MdiChildren.Length.ToString)
' the above code might be employed like this if the
' original parent assignment was correct
' Debug.WriteLine("MdiParent.Children=" + Me.MdiParent.MdiChildren.Length.ToString)
End Try
End Sub
Hope this helps, sorry i didn't monitor my emails more closely and get back to you before now.