Link to home
Start Free TrialLog in
Avatar of ofern01
ofern01Flag for United States of America

asked on

How Can I call a form that it's name is on a variable

I have a table with multiple record in it. Each record, when edit, must display a diferent entry form. when I bring up the record,I placed the name of the form on a variable, but now I need to call that form.

I need something like this:

Dim lcfrm As String = "FrmMntExtVnd"  ' this will be diferent for each record
Dim frmcall As windows.form
frmcall = CType(lcfrm, windows.form)
frmcall.Show()
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Use Activator.CreateInstance():

    Dim formName As String = "WindowsApplication1.FrmMntExtVnd"
    Dim frm As Form = DirectCast(Activator.CreateInstance(Type.GetType(formName)), Form)
    frm.Show()
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 ofern01

ASKER

Somehow I get an error saying a null reference on parameter not allowed. (with in the gettype()) and that I need to specify a New keyword
I tried the Ronald and worked fine. Later I will try to find out why that error when it shouldn't. I just don't have time now.
Thanks, That was great help