Can I call a method of an object in runtime by "object name" string?
Private Sub FormShow(FormName as string)
dim f as Form
f = FormName //?????
load f
f.show 1
End Sub
Can I reference to an object by help of its name (string) in runtime?
Re: Can I call a method of an object in runtime by "object name" string?
Quote:
Originally Posted by ultra2
Private Sub FormShow(FormName as string)
dim f as Form
f = FormName //?????
load f
f.show 1
End Sub
Can I reference to an object by help of its name (string) in runtime?
In order to reference an object...
VB Code:
Dim f As Form
Set f = Form2
f.Show
Re: Can I call a method of an object in runtime by "object name" string?
Why not just do
Private Sub FormShow(FormName as Form)
FormName.Show
End Sub
Re: Can I call a method of an object in runtime by "object name" string?
For that matter, why the sub at all. Form1.Show is less typing than creating the sub and typing FormShow Form1
Re: Can I call a method of an object in runtime by "object name" string?
The form name is a string and I get it from a database field IN RUN TIME.
It could work, but I have 200 form in my app so I need a more generally solution than this:
Private Sub FormShow(FormName as string)
if From1.name = FormName then From1.show
if From2.name = FormName then From2.show
if From3.name = FormName then From3.show
...
End Sub
Re: Can I call a method of an object in runtime by "object name" string?
Why would you need 200 forms? if you dont mind me asking.
It seems a little too much.
Re: Can I call a method of an object in runtime by "object name" string?
I don't know of any way to open a form in the way you want. If you want to open a form, use a select case statment:
VB Code:
Select Case FormName
Case "Form1"
Form1.show
Case "Form2"
...
End Select
This may not be easy, but I know of no other way (and it is easier than 200 if ... then statments)
Re: Can I call a method of an object in runtime by "object name" string?
I also could use the "Forms" array, but it only consist of the loaded forms and I dont want to load all the forms of my App.
Any other way to loop through all the forms of the app?
Re: Can I call a method of an object in runtime by "object name" string?
No, sorry. Only way apart from the Forms collection is to use a Select Case as Mikewitt posted.
VB Code:
Dim frm As Form
For Each frm In Forms
If frm.Name = strName Then frm.Show
Next frm