Question : using one procedure with for parameteres to open forms

I have the code below and i want to use it to open all forms. in it i supply only the name of the form to open and the MDI form .

it always passes the (Not IsNothing) condition and it fails and it fails.

.................................................................................................................

 Public Sub openRecForm(ByVal frm As Form, ByVal midfrm As Form)
        Dim recFld As Form = frm
        ' recFld = frm
        If Not IsNothing(recFld) Then
            If Not recFld.IsDisposed Then
                recFld.WindowState = FormWindowState.Normal
                recFld.BringToFront()
            Else
                recFld = New Form
                recFld = frm
                recFld.MdiParent = midfrm
                recFld.Show()
            End If
        Else
            recFld = New Form
            recFld = frm
            recFld.MdiParent = midfrm
            recFld.Show()
        End If
        recFld.Dispose()
        recFld = Nothing
    End Sub

Answer : using one procedure with for parameteres to open forms

Try this way instead
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
    Public Sub openRecForm(ByVal frm As Form, ByVal midfrm As Form)
        Dim recFld As Form = frm

        Dim f As Form = Application.OpenForms(recFld.Name)
        If f IsNot Nothing Then
            If Not recFld.IsDisposed Then
                recFld.WindowState = FormWindowState.Normal
                recFld.BringToFront()
            Else
                recFld = New Form
                recFld = frm
                recFld.MdiParent = midfrm
                recFld.Show()
            End If
        Else
            recFld = New Form
            recFld = frm
            recFld.MdiParent = midfrm
            recFld.Show()
        End If
    End Sub
Random Solutions  
 
programming4us programming4us