Open form by caption

I am wanting to create a "My Favorites" Form to store the top 10 forms/reports the users uses the most.

I have got 10 fields in each users record that stores the name of the form

I made a form with the following;10 command buttons, labels

The labels are bound to the users record which shows what the name of the form/report is.

How do I take the labels caption and open the form

Davids Learning



Answer this question

Open form by caption

  • arkiboys

    The way this code works is that it uses reflection to find the type for the form you want to create. A type is stored in an assembly. I'm using Assembly.GetExecutingAssembly to find the assembly in which the currently executing code (Button1_Click) is defined. As long as that assembly also contains the form, it will work without problems. If you put forms in other assemblies, you'll have a much tougher time finding them back. The best thing to do in that case is not just store the form name but also the assembly name (like "ClassLibrary1.Form2").


  • ar_pad

    can you clarify one assembly

    Still new to this!

    All of the strings that are in the labels text will be the forms name, like

    if label1's text has "registration"

    there will be a form that is called "registration"

    Do I need to include the .vb as seen in the solutions explorer at the end of the string

    Davids Learning


  • morfasie

    There are a lot of details but as long as all your forms are in one assembly, this might be helpful:

    Imports System.Reflection
    Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim frmname As String = "Form1"
    Dim asm As Assembly = Assembly.GetExecutingAssembly
    Dim asmname As String = asm.GetName().Name
    Dim frm As Form = CType(asm.CreateInstance(asmname + "." + frmname), Form)
    frm.Show()
    End Sub
    End Class



  • Open form by caption