Its a long story but what I need is to be able to load forms by using a string.
ie
Load strFormName
Anybody got any ideas?
Printable View
Its a long story but what I need is to be able to load forms by using a string.
ie
Load strFormName
Anybody got any ideas?
That's not possible with VB. The best you can do (if you know the names of the forms) is to set up a case statment like
Select Case strFormName
Case "MyForm1"
Load MyForm1
Case "MyOtherForm"
Load MyOtherForm
Case Else
MsgBox "Unknown form name"
End Select
Uh Uh Uh.
I have had this problem before. Instead of having the name of the form as a string, store a reference to the form.
e.g.
Code:Dim myForm As Form
'set the form reference
Set myForm = Form2
Load myForm
'or
myForm.Show
Problem is I've inherited an app' that has 10 forms, with 10 buttons on each form that load one of the ten forms. What has happened is that there was 10 lots of
button1_click 'etc
anotherform.show
on each form. Absolute hell!
I want to write it as
cmdbuttons_click(index as integer)
dim myobj as myformhandler
dim strname as string
strname=myobj.formname(index)
load strname
Anymore ideas??
Does the third button (for example) on each for load the same form? If so then in your new cmdbuttons_click event you can do something like
Select Case Index
Case 0
Load MyForm1
Case 1
Load MyForm2
Case 2
Load MyOtherForm
End Select
Yes, it does.
The problem with doing it like that is that I'll have a big case statement that will be the same across 10 forms.
I've got all the form names in a DLL in an enum so if I remove or add any forms I only have to do it once. This is what I'm trying to get working.
There just has to be a way!!!!!!
Does you app have a code module? If not then create one and a routine in that module that you call using the Index of the button clicked. The routine might look something like
Public Sub LoadForm(intButton as Integer)
Select Case intButton
Case 0
Load MyForm1
Case 1
Load MyForm2
Case 2
Load MyOtherForm
End Select
End Sub
And you would call the routine from the Click event of the buttons as follows
LoadForm Index
Doh!
Cheers Martin.
Ok i know this wont work but, Is there another property than forms that contains all forms that are not loaded?Code:For each n in forms
if n.name=string then show n
next n