by Mihir Solanki (2 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 5.0
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (5 Votes)
This code will close all other MDI Child except the current activated one.Simply put this procedure in Module or Form itself..There are two different way to use it.
Option Explicit
'+++++++++++++++++++++++++++++++++++++
' First Style
' Use private procedure in Form
'+++++++++++++++++++++++++++++++++++++
Private Sub Form_Activate()
UnloadOthers
End Sub
Private Sub UnloadOthers()
Dim frm As Form
For Each frm In Forms
If frm.Name <> Me.Name And Not (TypeOf frm Is MDIForm) Then
Unload frm
End If
Next
End Sub
'+++++++++++++++++++++++++++++++++++++
' Second Style
' Use Public Procedure in Module
'+++++++++++++++++++++++++++++++++++++
'Form Code
Private Sub Form_Activate()
UnloadOthers me.Name
End Sub
'Module Code
Public Sub UnloadOthers(frmName as string)
Dim frm As Form
For Each frm In Forms
If frm.Name <> frmName And Not (TypeOf frm Is MDIForm) Then
Unload frm
End If
Next
End Sub