I want a certain form to be unloaded only when there is no other form loaded, how do I check if any of the other forms are still loaded

I don't know if this is right but just try it

Function LookForForm()
    Dim frm As Form
    
    For Each frm In Forms
        If frm.Name <> mdiMain.Name Then
            ...put your code here
        End If
    Next
End Function

I've tried it and it works. I put it in the timer_timer sub which I have in the form that I want last unloaded, so it might take up to a minute till the program ends. Is there a better place to put it

I've put it in all the other forms unload event.
Thanks for your help

put it in the module so that you can call the sub when you needed. I used that everytime I open a MdiChild form so that i dont need to unload the forms that are already opened.

Private Sub SectionCmd_Click()
   LookForForm
   SectionForm.Show
End Sub

Private Sub DepartmentCmd_Click()
   LookForForm
   DepartmentForm.Show
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.