Solved

Problems getting app to stop running when closed.

Posted on 2000-04-20
6
181 Views
Last Modified: 2012-05-04
What is the proper way to code for the app being closed?  When I close my app, it keeps running in the background and I don't know how to get it to stop.  I'm sure this is a simple question, I just don't have any clue.
0
Comment
Question by:jasonboetcher
6 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2734993
it depends on what objects you may be creating but as for closing all the forms.  in your main form use this:

Private Sub Form_Unload()
   Dim frm As Form
   For Each frm in Forms
     If frm.hWnd <> Me.hWnd Then
        Unload frm
     End If
   Next
   Unload Me
End Sub
0
 

Expert Comment

by:moterk
ID: 2734999
Does your app have any forms?  Or just a sub main?  To quit a program with just a sub main, use the END command.  If you have forms unload your startup form and in its unload event use the END command.  Is is also best to set all objects you have created to nothing.
0
 
LVL 2

Expert Comment

by:Sage020999
ID: 2735000
Are you using class modules or databases?  Often times that I have seen that problem is because forms, class, or databases aren't being closed and set to nothing.  Here closing code.


Sub FileExit()

  Dim LogRS As DAO.Recordset
  Dim ctr As Integer
  Dim DB As DAO.Database
  Dim strSQL As String
  Dim lngRC As Long
  Dim lngRC2 As Long
 
  On Error Resume Next



   'Close all recordsets and databases
    Set LogRS = Nothing
    Set DB = Nothing
    Set frmMain.DTDs = Nothing
    Set frmMain.InvcDs = Nothing
    Set frmMain.InvDs = Nothing
 
    For ctr = 0 To Forms.Count - 1
      If Forms(ctr).Name <> "frmMain" Then
        Unload Forms(ctr)
      End If
    Next ctr
    'Now unload frmMain
    For ctr = 0 To Forms.Count - 1
        Unload Forms(ctr)
    Next ctrEnd

End Sub
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 1

Accepted Solution

by:
derekcmartin earned 25 total points
ID: 2735159
And if all else fails, use

private sub form1_unload()
     end
end sub
0
 

Author Comment

by:jasonboetcher
ID: 2735317
I have a main form and many sub forms.  I was setting each of the forms to nothing as they were being unloaded.  The piece I was missing was the End command.
0
 
LVL 1

Expert Comment

by:derekcmartin
ID: 2735617
Thanks!  8o)
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

832 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