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.
LVL 1
scj1Asked:
Who is Participating?
 
VbmasterConnect With a Mentor Commented:
Sometimes the simplest method is the best. ;)

Unfortunately I have no idea what you mean with datareports, I have done almost nothing with DAO databases.

0
 
VbmasterCommented:
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.
0
 
watyCommented:
' #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
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
VbmasterCommented:
I have to add that waty's solution only works in VB6.
0
 
GuryTraubCommented:
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
0
 
scj1Author Commented:
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.
0
 
scj1Author Commented:
Thanks,

StuJ
0
All Courses

From novice to tech pro — start learning today.