Chat LIVE With Programming Experts! There Are 23 Online Right Now...

 

Code Snippets

  

Visual Basic Source Code


Welcome to Dream.In.Code
Become a VB Expert!

Join 244,216 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,461 people online right now. Registration is fast and FREE... Join Now!





Close all forms in your application

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

Submitted By: PsychoCoder
Actions:
Rating:
Views: 3,609

Language: Visual Basic

Last Modified: August 14, 2008

Snippet


  1. Private Sub CloseAllForms()
  2.     Dim frm as Form
  3.     'First we want to loop through all the
  4.     'Forms and close them (We close the current Form last)
  5.     For Each frm In Forms
  6.        'Make sure we arent looking at the current Form
  7.        If frm.hWnd <> Me.hWnd Then 
  8.            'Unload this Form
  9.            Unload frm
  10.            Set frm = Nothing
  11.        End If
  12.    'Now get the next Form
  13.    Next frm
  14.  
  15.    'Now unload the current Form
  16.    Unload Me
  17. End Sub

Copy & Paste


Comments


Jaalenn 2008-11-17 08:10:38

Oddly enough I was taught to always use the Unload Me command for my forms... Go Figure!!

LifeHacker 2009-01-16 04:05:55

I could not get this to work. In the line For Each frm In Forms Forms is not declared


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month