Detect # of forms opened automatically
Hi!
I would like to be able to automatically count the number of forms currently opened when the user clicks a menu item. How do I do this?
I basically want to make sure each child form is unloaded before i close the parent mdi form.
Any help is appreciated!
~goddess
[email protected]
Re: Detect # of forms opened automatically
Re: Detect # of forms opened automatically
Hey there, see if this code does what you're looking for...
Dim frm as Form
for Each frm In Forms
if frm.MDIChild = true then Unload frm
next
I haven't tested that so I can't swear on my life that it will work but maybe get you in the right direction? Good luck!
Jeff
Re: Detect # of forms opened automatically
is there such a thing as an 'isLoaded' check? i think that would capture what I am trying to do.
The code you posted gave me an 'invalid property value' error, but it was a great idea!
~goddess
[email protected]
Re: Detect # of forms opened automatically
Actually, I changed it to frm.visible = true then . . .
and it worked great!!
Thanks for the kick start!
~goddess
[email protected]
Re: Detect # of forms opened automatically
Hahaha, I just tested some code with frm.Visible and it worked out so as I came back to post it for ya I noticed your message- great minds... :)
Re: Detect # of forms opened automatically
This adds to what everyone else has posted:
in parent form:
option Explicit
private Sub MDIForm_Load()
' or form1.show if you want
Load Form1 'child
Load Form2 'child
Load Form3 'not a child
End Sub
private Sub MDIForm_QueryUnload(Cancel as Integer, UnloadMode as Integer)
Dim intCount as Integer
' unloads all forms
' note forms(0) is the parent form which as you know will be unloaded
' by the its own unload method
' The forms collection begins at 0 and Forms.Count gives the number of
' forms in the collection, so you need to -1
for intCount = (Forms.Count - 1) to 1 step -1
If Forms(intCount).MDIChild then
MsgBox Forms(intCount).Name & " is a child"
else
MsgBox Forms(intCount).Name & " is not a child"
End If
Unload Forms(intCount)
next
End Sub