title: Access forms in another project in VB.net 2010
body: <p>I am using VB.net 2010 and I have two projects: <strong>SQLtesting</strong> and <strong>Controls</strong>. Their physical locations are:</p>
  
  <p><strong>C:\My Documents\Visual Studio 2010\Projects\SQLtesting\SQLtesting\ [forms reside here]
     C:\My Documents\Visual Studio 2010\Projects\Controls\Controls\ [forms reside here]</strong></p>
  
  <p>The code shown below works fine. I run it from the project <strong>SQLtesting</strong>. It loads a listbox and a checkedlistbox with the controls found on a form. I can change the value of the <strong>ProjAndForm</strong> field to any form within the <strong>SQLtesting</strong> project and get the form's controls. The forms are not actually opened/shown and they are not suppose to be.</p>
  
  <p>I would like to be able to access forms in other projects i.e. 
     *<em>C:\My Documents\Visual Studio 2010\Projects\Controls\Controls*</em> 
  while running the code from the SQLtesting project.</p>
  
  <p>In actual use, (when this application is an .exe) the user (developer) will enter the Project Name, Form name and whatever else this requires and click on Button7. There cannot be any hardcoding as in my example code. This application will be installed on individual pc's or on a network so the code must work based on what the developer enters.</p>
  
  <p>What I really need is a way to POINT to another project and form and still use my code. 
  I believe the statements needed would precede the following 3 statements I have.</p>
  
  <pre><code>ProjAndForm = "SQLtesting.Form1"
  FormInstanceType = Type.GetType(ProjAndForm, True, True)
  objForm = CType(Activator.CreateInstance(FormInstanceType), Form)
  </code></pre>
  
  <p>Currently, if I change the value of <strong>ProjAndForm</strong> to <strong>"Controls.Form66"</strong> an exception is thrown on the <strong>FormInstanceType</strong> statement. </p>
  
  <p><strong>Could not load type 'Controls.Form66' from assembly 'SQLtesting, 
     Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.</strong></p>
  
  <p>As I said above, the code works fine and provides exactly what I want as long as I 
  reference a form in the current project SQLtesting.</p>
  
  <p>Can anyone help me with this?</p>
  
  <p>Thank you.</p>
  
  <pre><code>Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As
  </code></pre>
  
  <p>System.EventArgs)      Handles Button7.Click</p>
  
  <pre><code>    Dim CtlType As Type
      Dim FormInstanceType As Type
      Dim index As Integer 
      Dim objForm As Form
      Dim ProjAndForm As String
      Dim TypeName1 As String
      Dim TypeName2 As String
  
      ListBox1.Sorted = True
      ListBox1.Items.Clear()
  
      CheckedListBox1.Sorted = True
      CheckedListBox1.Items.Clear()
      CheckedListBox1.CheckOnClick = True
  
      ProjAndForm = "SQLtesting.Form1"
      FormInstanceType = Type.GetType(ProjAndForm, True, True)
      objForm = CType(Activator.CreateInstance(FormInstanceType), Form)
  
      For Each ctl As Control In objForm.Controls 
          CtlType = ctl.GetType
          TypeName1 = CtlType.ToString.Substring(21) ' Remove system.windows.forms prefix
          index = CheckedListBox1.FindStringExact(TypeName1)
          If index = -1 Then
              CheckedListBox1.Items.Add(TypeName1)
          End If
          TypeName1 = TypeName1 &amp; ":" &amp; ctl.Name &amp; ":" &amp; ctl.Text
          ListBox1.Items.Add(TypeName1.ToString)
      Next ctl
  
  End Sub
  </code></pre>