|
|
Title | Use a collection to display one instance of a form given its name |
Keywords | form, form name, show form |
Categories | Controls, Software Engineering |
|
|
Store the form objects in the collection using their names as keys. Use the collection to display the forms when needed.
This has the advantage that the forms are placed in the collection when the program starts so accessing the forms later is fast.
One disadvantage is that this method only allows the program to display one instance of each form.
|
|
Private FormObjects As New Collection
' Load the FormObjects collection with form
' objects using their names as keys.
Private Sub Form_Load()
FormObjects.Add Form2, "Form2"
FormObjects.Add Form3, "Form3"
End Sub
' Display the named form.
Private Sub cmdShowForm_Click()
Dim frm As Form
On Error Resume Next
Set frm = FormObjects(txtFormName.Text)
If Err.Number Then
MsgBox "Unknown form name"
Exit Sub
End If
On Error GoTo 0
frm.Show
End Sub
|
|
|
|
|
|