|
|
Title | Use a command objects to display multiple instances of a form given its name |
Keywords | form, form name, show form |
Categories | Controls, 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
|
|
|
|
|
|