Solved

close all forms

Posted on 2000-04-27
8
164 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
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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 27

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now