-
Hi all,
I need to seek for the content of a label in all open forms of an MDI. To be more specific, of all the child forms that have been created within the MDI, I need to look for the forms that have a label named MyLabel and return the content of it.
These forms have all been created using the following code:
Code:
Dim FrmD As TemplateForm
Set FrmD = New TemplateForm
FrmD.Show
where of course TemplateForm is a child form.
Does someone of you have a good seek and destroy code for this?
Best regards to you all, let the forum live!
W.
-
Loop through the Forms collection and with those forms whose .Parent is "MyForm", loop through the controls for a Label control.
Or have I got it totally wrong? I am a bit rusty on MDI...
Cheers,
P.
-
i believe that could work, still do you have a code example to give?
Thanks,
W.
-
You should have another collection to which you add to/remove childs from the mdiparent, then you can loop trough that collection. The controls on the forms are in controls object which you can loop trough using for each statement. use name property to catch the label name
-
Would you believe I have managed to work it out.
The following code looks through the forms collection, and then through all the controls for that form and will display the caption of the control Label3.
Be aware that the Forms collection only contains the forms that are loaded, not forms that are part of the project and not yet loaded. Also the comparison on the Label3 name IS case sensitive so it will not see label3 as opposed to Label3.
Code:
Dim i As Integer
Dim ctrl As Control
For i = 0 To Forms.Count - 1
MsgBox Forms(i).Name
For Each ctrl In Forms(i).Controls
If ctrl.Name = "Label3" Then
MsgBox ctrl.Caption
End If
Next
Next i
I am still amazed I have worked it out.
Hope this helps.
-
WOW! That looks like pure gold to me :) I just have to substitute your
MsgBox Forms(i).Name
with the filter on the form name ("TemplateForm") done with a simple conditional IF, and then if this works I'm done!
I'll try it tonight, thanks a damn lot,
W.