Solved

close all forms

Posted on 2000-04-27
8
165 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Exit a vb6 apps when a calling it apps closes 15 42
Child Form in front 4 37
MsgBox 4 45
Create Files based on Cell Values in a Range in Excel 12 17
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 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

23 Experts available now in Live!

Get 1:1 Help Now