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

[443 byte] By [DavidsLearning] at [2007-12-23]
# 1
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

nobugz at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

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

DavidsLearning at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3
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").

nobugz at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...