Solved

Problems getting app to stop running when closed.

Posted on 2000-04-20
6
179 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…

758 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

18 Experts available now in Live!

Get 1:1 Help Now