Link to home
Start Free TrialLog in
Avatar of ZeonFlash
ZeonFlash

asked on

Opening forms based on form Type

I'm currently trying to create a unified function for opening some forms, but there are some problems when trying to utilize the Types.  

For example, lets say I have 5 forms:  Form1, Form2, etc.

Calling the function, I would like to use:  OpenFunction(GetType(Form1))

A sample of what I've tried is:

    Public Function OpenForm(ByVal FormType As Type)
        Dim frm As New Form

        'Find if a form of that type is already open (found in the Forms Collection).  Returns a reference to the form.
        frm = Forms.FindForm(FormType)

        'If the form is already open, bring it to the front
        If Not frm Is Nothing Then
            frm.BringToFront()
        Else
            'Otherwise, the form is not open, so create a new one
            frm = New ??? 'Here is the problem
        End If

        'Show the form
        frm.Show()
    End Function

Is there any way to create a New form, given the Type?  
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ZeonFlash
ZeonFlash

ASKER

Works like a charm.  Thanks!