Solved

close all forms

Posted on 2000-04-27
8
169 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 50 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
Independent Software Vendors: 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Saving history changes to sub form 4 52
vb6 connector to mongodb 2 141
converting visio 2010 to powerpoint 2010  - formatting issues 5 109
Export Data to Different .csv Files 26 121
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

733 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