Is there a way to tell if there is a child form active on an mdi form? I am getting an error when I try to use the activeform property when there are no active forms. Is there an easy way to check this?
Printable View
Is there a way to tell if there is a child form active on an mdi form? I am getting an error when I try to use the activeform property when there are no active forms. Is there an easy way to check this?
Check to see if the ActiveForm property is Nothing first before using it..... I think there is also a ChildCount or a ChildFormCount, some sort of count property that returns the number of child forms for an MDI.
Doing this:
If frmMDI.ActiveForm = Nothing then
msgbox "nothing"
end if
ends up giving me an invalid use error. I will check the other suggestion you gave though.
I need to know the count of the child forms that are active not just the count. There doesn't seem any properties that are built in. Please let me know if you have other suggestions
You can have several child open but only one of them will be active so the number of active forms will be 1.
In order to check the active form and not getting error you can use an error treatment
VB Code:
on error goto error 'check active form exit sub error: MsgBox "no form active" End Sub
Thanks. Is there anyway to check to see how many child forms are open?
There are few different ways to do this:
1. Create a Public intNumberOfChilds As Integer at the module level and increment it on evry Child's Form_Load event.
2. Loop through Forms collection and check wheter or not frm.MDIChild = True and if YES then you would just increment some local counter.
3. Create MDIForm Public Property to a number of currently loaded childs (it will be incremented on each child's form_load)
In case 1 and 3 you will have to decrement number on each child Unload event.