Click to See Complete Forum and Search --> : Setting a form object variable using a form name string?


Martin Thorpe
July 26th, 1999, 10:00 AM
In MS Access the Open form statement takes a string as the name of the form. In VB6/SQL server I have a list in a listbox of the names of many crystal report files.
When one is picked, the chosen name is placed in the ReportFileName property of the crystal control. The name is then used to check a table of reports on SQLsrvr to
see if it needs parameters before running the report, and if so, I want to be able to open a 'dlgformname' to get them, where formname is the same name as was chosen
from the list. However, there seems to be no way to assign a form object reference to a form object variable using just the string name of the form somehow to resolve
the object expression to the form class. Am I missing something? Ideally it would be functionally like:
Dim genericform as Form
Set genericform = New 'formname' where formname is a string variable
genericform.show

Is there any way to do this using a string variable containing the name of a form?

Tomaz Stih
July 30th, 1999, 10:43 AM
Phuuh,

1. ok, you can browse trough all available forms using the Forms collection:

' the following example changes all form captions
Dim vForm as Variant
for Each vForm In Forms
vForm.Caption="Form"
next vForm



2. you can also get type of every variable using

vt=VarType(var)



3. now what you have to do is either find desired type variable or find a form and then do a select case statement

select case
case 1:
set newform=new form1
case 2:
set newform=new form2
end select



But do be careful with the lifetime of objects...

Hope it helps at least a little ( enough for a *rate* ;-) ),
Tomaz

---------------------------------------------
Tomaz Stih, B.Sc.CS tomaz@nameco.com
Ob sotoccju 10 Nameco Group
SI-1000 Ljubljana http://www.nameco.com
Europe

Martin Thorpe
July 30th, 1999, 08:26 PM
Hi Tomaz,

Your suggestion will work for open forms, but that is not relevant to the problem because there is no instance of the form open in the module which is trying to decide to open one. As I understand it, non-loaded forms of a project do not appear in the Forms collection, and I'm talking about a large project with a lot of different forms, so the suggested solution would not work. Its the form1 form2 in your example which needs to be dynamic somehow from the available forms in the project - loaded or not.
Cheers

Martin