3 Replies - 2311 Views - Last Post: 15 May 2010 - 02:30 AM

#1 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Close all forms in your application

Posted 14 August 2008 - 05:34 PM

Description: This is the proper way to close all the forms in your application. Some say to just call End but that just crashes the program without raising an error
Private Sub CloseAllForms()
    Dim frm as Form
    'First we want to loop through all the
    'Forms and close them (We close the current Form last)
    For Each frm In Forms
       'Make sure we arent looking at the current Form
       If frm.hWnd <> Me.hWnd Then  
           'Unload this Form
           Unload frm
           Set frm = Nothing
       End If
   'Now get the next Form
   Next frm

   'Now unload the current Form
   Unload Me
End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: Close all forms in your application

#2 Jaalenn   User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 105
  • Joined: 17-November 08

Re: Close all forms in your application

Posted 17 November 2008 - 06:10 AM

Oddly enough I was taught to always use the Unload Me command for my forms... Go Figure!!
Was This Post Helpful? 0
  • +
  • -

#3 LifeHacker   User is offline

  • New D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 30
  • Joined: 27-July 08

Re: Close all forms in your application

Posted 16 January 2009 - 02:05 AM

I could not get this to work. In the line For Each frm In Forms Forms is not declared
Was This Post Helpful? 0
  • +
  • -

#4 orlin369   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 15-May 10

Re: Close all forms in your application

Posted 15 May 2010 - 02:30 AM

nice it is vary helpful..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1