Solved

Problems getting app to stop running when closed.

Posted on 2000-04-20
6
185 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
[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
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 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…

687 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