Link to home
Start Free TrialLog in
Avatar of scj1
scj1

asked on

Loading forms from (string) names

I need to be ableto load forms and manipulate then when I do not necessarily know the name at design time. For example, I could plug in additional forms and get the file and form names from an external text file.

It isn't important actially to "add" the form at run time, just load it into focus from a string name at run time.
Avatar of Vbmaster
Vbmaster

You could solve this by using a simple SelectCase..EndSelect block structure like this

Select Case FormNameToLoad
Case "frmMain"
  Load frmMain
Case "frmAnother"
  Load frmAnother
End Select

This is probably the only solution possible I'm afraid. You can scan thru the .vbp file to see all the possible form names. Lines starting with 'Form=' contains a form name.
' #VBIDEUtils#************************************************************
' * Programmer Name  : Waty Thierry
' * Web Site         : www.geocities.com/ResearchTriangle/6311/
' * E-Mail           : waty.thierry@usa.net
' * Date             : 20/09/1999
' * Time             : 11:59
' **********************************************************************
' * Comments         : Loading a Form using a String
' *
' *
' **********************************************************************
Sub LoadFormByString(sFormName As String)
   Dim NewForm As Form
   Set NewForm = Forms.Add(sFormName)
   NewForm.Show
End Sub
I have to add that waty's solution only works in VB6.
Hey you can get the string name of the form with your host (container) father form (MDI..)
This can be your line to get the name of the form

name = MDImain.ActiveForm.name
Avatar of scj1

ASKER

The first comment by vbmaster is the one I used (its a VB6 Enterprise app so it worked perfectly).

If you post it again you can have the points. Incidently, if you know how to do the same with datareports I'd appreciate it (i've increased the points slightly as a sweetner!)

Thanks,

StuJ.
ASKER CERTIFIED SOLUTION
Avatar of Vbmaster
Vbmaster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of scj1

ASKER

Thanks,

StuJ