Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleUse a command objects to display multiple instances of a form given its name
Keywordsform, form name, show form
CategoriesControls, Software Engineering
 
Create form maker objects to create the forms. Save maker objects in a collection using the form names as keys. To create a form, retrieve the corresponding maker object and use it to build the form.

My book Ready-to-Run Visual Basic Algorithms, Second Edition has more information on command objects.

 
Private FormMakers As New Collection

' Load the collection of form makers.
Private Sub Form_Load()
Dim maker As Object

    Set maker = New MakeForm2
    FormMakers.Add maker, "Form2"
    
    Set maker = New MakeForm3
    FormMakers.Add maker, "Form3"
End Sub

' Display the named form.
Private Sub cmdShowForm_Click()
Dim maker As Object
Dim frm As Form

    On Error Resume Next
    Set maker = FormMakers(txtFormName.Text)
    If Err.Number Then
        MsgBox "Unknown form name"
        Exit Sub
    End If
    On Error GoTo 0
    
    Set frm = maker.MakeForm
    frm.Show
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated