Advertisement
7_2009-2012 Custom Controls/ Forms/ Menus #230907

Close all MDI Child except me

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.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
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
Original Comments (3)
Recovered from Wayback Machine