?
Solved

close all forms

Posted on 2000-04-27
8
Medium Priority
?
171 Views
Last Modified: 2010-05-02
What is the easiest way to make VB close all open forms.  Essentially when a user clicks on btnExit it should loop thru the app and close all the forms.

thanks
0
Comment
Question by:sopheak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 28

Accepted Solution

by:
AzraSound earned 200 total points
ID: 2757499
put this in the forms unload event

Dim frm As Form
For Each frm in Forms
If frm.hWnd <> Me.hwnd Then Unload frm
Next
Unload Me
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2757549
Private Sub btnExit_Click()
    Unload Me
End Sub



Private Sub Form_QueryUnload(...

Dim frm as Form

For Each frm In Forms
    If Not frm Is Me Then
        Unload frm
        Set frm = Nothing
    End If
Next

End Sub
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2757554
Oops, the code should be in the Unload event...

Private Sub Form_Unload(...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:Glen Richmond
ID: 2757785
Public Sub UnloadAllForms()
   Dim Form As Form
   For Each Form In Forms
      Unload Form
      Set Form = Nothing
   Next Form
End Sub

just pop this in a module and call it when ever you want to close all forms..


0
 
LVL 28

Expert Comment

by:Ark
ID: 2757792
Though MS is not recommended, but End works in most cases
Cheers
0
 

Expert Comment

by:shideyi
ID: 2757824
use the following code
Private Sub btnExit_Click()
  'define aForm as Form Object
  Dim aForm As Form
 
  'Forms refer to all loaded forms
  For Each aForm In Forms
    'loop through all loaded forms and unload them
    Unload aForm
    'use this statement to release the memory allocated for this form
    Set aForm = Nothing
  Next aForm

End Sub
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2757826
hey lets see how many times we can post this  =)
0
 

Author Comment

by:sopheak
ID: 2757836
Sorry for the delay, but I want to test a few of the answers

Thanks much
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question