
Showing VB Forms via string variable
In follow-up to an earlier post, I asked how to load a VB6 form based on a
string variable (i.e. similar to the Access DoCmd.OpenForm strFormname). That
problem was solved via the Forms.Add command to load it into the collection.
But now I need to find a way to show a particular form based on a name
contained in a string variable. I need a form to 'pop-up' based on a user
selected check box. The name of the form is stored in a table and is transfered
to the tag of the control on form load. How can I take this string value in
the tag property of the control and open the corresponding form? The .Show or
.Load commands do not seem to accept a string variable (only an integer index).
I am looking for something similar to Show(strFormname). I have tried
declaring a new form and setting the .Name property equal to the string, but VB
reports that the name is a read-only property at runtime.
The only solution I have found is to loop through all forms in the collection
until a matching name is found:
Dim frm as Form
For each frm in Forms
if frm.Name = strFormname then
frm.show
exit sub ' Kick out of loop
end if
Next frm
This works but seems a little inefficient, especially if many forms are loaded.
Is this the only solution in VB6, or is there another way to open a particular
form based on a string parameter?
Thanks in advance (and thanks for previous help!).
Steve Herriford
Indianapolis, IN