Click to See Complete Forum and Search --> : Visual Basic


vijaypathak
April 17th, 2001, 11:07 PM
Is there any way by which i can store the name of a form in a variable and then load the form using this variable.

Thanks.
Pathak

terryl
April 18th, 2001, 02:23 AM
try this:


Dim fMainForm as frmMain

set fMainForm = new frmMain
fMainForm.Load




Where frmMain is the name of your form.
you may declare fMainForm as public so that you can access it any where in the project.

vchapran
April 18th, 2001, 08:07 AM
You can use something like that:

'In Module
option Explicit
public strFormName as string

public Sub LoadPrevious()
Select Case strFormName
Case "Form1"
Form1.Show
Case "Form2"
Form2.Show
Case "Form3"
Form3.Show
End Select
End Sub



In your forms in the place you want assign a new value to strFormName. Let's say if you do in Form1:

private Sub Form_Unload(Cancel as Integer)
strFormName = "Form1"
End Sub



then later you can load Form1 from any place of your code by calling LoadPrevious. The scenario might be more complicated, like you can use array to store several values.
HTH
Vlad

John G Duffy
April 18th, 2001, 03:36 PM
Dim x as Form, strName as string
strName = Text1.Text
set x = Forms.Add(strName)
x.Show





John G

vijaypathak
April 22nd, 2001, 01:05 AM
This I have tried, here I know frmmain is the form to be opened but i want "frmmain" to be stored in a variable (bcoz i am retriveing the forms name from a table a table)

vijaypathak
April 22nd, 2001, 01:19 AM
Thanks, this solved my problem