?
Solved

Problems getting app to stop running when closed.

Posted on 2000-04-20
6
Medium Priority
?
188 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Accepted Solution

by:
derekcmartin earned 100 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…
Suggested Courses

762 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