Click to See Complete Forum and Search --> : Detect # of forms opened automatically


goddess_spanky
August 10th, 2001, 03:47 PM
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
goddess_spanky@hotmail.com

Kdev
August 10th, 2001, 03:53 PM
Forms.Count

-K

Ghost308
August 10th, 2001, 03:54 PM
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

goddess_spanky
August 10th, 2001, 04:01 PM
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
goddess_spanky@hotmail.com

goddess_spanky
August 10th, 2001, 04:02 PM
Actually, I changed it to frm.visible = true then . . .
and it worked great!!
Thanks for the kick start!

~goddess
goddess_spanky@hotmail.com

Ghost308
August 10th, 2001, 04:10 PM
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... :)

Raptors Fan
August 11th, 2001, 11:41 AM
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