Results 1 to 14 of 14

Thread: [RESOLVED] Previous Instances Remaining

Hybrid View

  1. #1
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Previous Instances Remaining

    Quote Originally Posted by DaWolf
    How do you get the instance to release properly when the X is clicked?
    There are number of thing to look upon closing your app the following "list" is just an idea:

    - close all global connections, recordsets, etc (if any)
    - destroy all global objects
    - close all documents (if automation is in place)
    - loop through forms collection and close each form individually
    - for each form (form_unload or queryunload events can be used)
    ... - close any open local connection, etc...
    ... - destroy all form level objects

    ... and so on and so forth ...

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Previous Instances Remaining

    You can try something like this,

    Code:
    Option Explicit
    Dim terminate_app As Boolean
    
    Private Sub Form_Load()
        If App.PrevInstance Then
            terminate_app = True
            MsgBox "A copy of My Program is already loaded!", vbInformation
            Unload Me
            Exit Sub
        End If
    
    ' YOUR CODE HERE
    
    End Sub
    
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    	If terminate_app = True Then Exit Sub ' only run on normal exit
    
    ' Stop timers, close open files, save user settings, etc,etc,
    
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    
        Dim i As Integer
        ' unload forms 
        For i = Forms.Count - 1 To 0 Step -1
            Unload Forms(i)
        Next i
        
        'Set Form1 = Nothing
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width