• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 469
  • Last Modified:

Open Form Based On Table Value

I have a form with a combo on it that cross refrences which form to open based on the selection.  I have this half working.  It does the sql connection and looks up the value but stops and gives an error at the Show refrence in my code

I keep getting an error of
Unable to cast object of type 'system string' to type 'System.Windows.Forms.IWin32Window'.

so I think that it is having trouble taking the value from my table, which is the actual form name to open and translating to mytablevalue.show()
0
H-SC
Asked:
H-SC
  • 5
  • 4
1 Solution
 
Jeff CertainCommented:
Please post your code.

However, the form name is not the form. You may want to do something like this:

Dim formName as string = ' Get the name here
Dim frm as Form
Select Case formName
  Case "myForm1"
    frm = new myForm1
  Case "myForm2"
    frm = new myForm2
End Select
frm.Show
0
 
VBRocksCommented:
He're another way of doing it:

Let's say your combobox is named "Combobox1":

        'Set this to the name of your project (mine is "Expert")
        Dim sProjectName As String = "Expert"

        Dim frm As Form = _
            Activator.CreateInstance(System.Type.GetType(sProjectName & "." & ComboBox1.Text))

        frm.Show()


0
 
H-SCAuthor Commented:
Chaosian,

Here is the code that I currently have:

 Dim conn2 As New SqlClient.SqlConnection("Server= ---------;Database= -------;Trusted_Connection=yes")
        Dim sSQLCMd2 As String = ("select screen from modules where module='{m}'")
        sSQLCMd2 = Replace(sSQLCMd2, "{m}", Combobox1.Text)
        Dim scCmd2 As New SqlClient.SqlCommand(sSQLCMd2, conn2)
        conn2.Open()
        main.Show()
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
H-SCAuthor Commented:
VBRocks,

I keep getting the following error....

{"Value cannot be null.  Parameter name: type"}
0
 
VBRocksCommented:
Put a break point on the Activator.CreateInstance line of code, and check the following:

What does this contain:   sProjectName & "." & ComboBox1.Text

0
 
H-SCAuthor Commented:
VBRocks,

It shows the project name as the name of my project  and the form name is the form that I selected in the dropdown that is a form in my project called form2
0
 
VBRocksCommented:
So, can you show me exactly?  

Example:  In the Expert project, to open frmMain, It should be like this:  "Expert.frmMain"

Also, do you have your form in a namespace?

0
 
H-SCAuthor Commented:
it looks like the above...mine is PROJ5.form2

I dont think that either of the forms are in a unique namespace
0
 
VBRocksCommented:
Ok, one possibility is the casing.  Make sure you have the correct case for the names.

For example, "PROJ5" should be exact, not "proj5" or "Proj5"
If form2 is actually "Form2", then correct that and try it again.

So, perhaps it should be like this:
    PROJ5.Form2


0
 
H-SCAuthor Commented:
VBRocks,

That was the key....I had form2 in the table as form2 and not Form2.  Many thanks
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now