title: VB 6 crash on exit
body: <p>I have a legacy vb6 app that crashes on exit - both as an executable and in the IDE. How can I avoid the crash?</p>
  
  <ul>
  <li>I am currently unloading the forms (except the frmmain) in <code>form_unload</code>, releasing all the ADODB RecordSets, setting all the boundcollections = nothing. </li>
  <li>I have attempted to <code>SetErrorMode SEM_NOGPFAULTERRORBOX</code> in the <code>form_terminate</code> event and that has not stopped the error from occurring. </li>
  <li>I have also checked for subclasses being instantiated in my code and found none. </li>
  <li>I have checked into the components from outside Microsoft that are used - they are the ComponentOne flexgrid 8 spelling 8 and ComponentOne sizer control. An extensive web and forum search has not turned up any known problems similar to mine for these controls. </li>
  </ul>
  
  <p>The issue does not seem to occur if I shut down the program before actually doing anything. However loading the bound controls seems to be near where the problem is rooted, in spite of repeatedly stepping with the debugger it seems that the start of the problem "moves around". The problem occurs with the programmatic exit, the "X" and the IDE "end" control
  The error message is 
  <code>The instruction at "0x77d042b8" referenced memory at "0x055c9028". The memory could not be "Read"</code>. The title in the error box is a tool tip (differing at different times) from inside my app
  I have put breaks when stepping through the code - the app crashes on the exit sub line at the Form_Unload event</p>
  
  <p><strong>ADDED</strong><br>
   I realized that I should have included some other information with my original post. I was very tired and frustrated when I made it and sorry it was so difficult to read.<br>
  Now<br>
  1) I do have the latest service pack (6) installed, and the latest builds of the components<br>
  2) doing a debug in my VS2010 ide (which is on the same server) I got a very long stack dump beginning with OLEAUT32.dll, I updated that DLL but found no change<br>
  3) I am actually running (and working on) the program through a remote desktop connection. The program crashes on my desktop as well as on the users terminal server connections.<br>
  4) The OS I am running under is Windows Server 2003<br>
  5) the code I am running is<br>
  'code'</p>
  
  <pre><code>    Private Sub Form_Unload(Cancel As Integer)
          Set rsChild = Nothing
          Set rsCaseFile = Nothing
          ' many similar record sets closing
          ys.CloseConnection
          Set ys = Nothing
          UnloadAllForms (Me.Name)
          ' closeing bound collections 
          Set bndChild = Nothing
           Set bndAuth = Nothing
           ' more bound collections closed
           ' i had added the next two lines but it made no difference
           frmmain.close
           Set frmMain = nothing 
           getout
      end sub
      Public Sub UnloadAllForms(Optional FormToIgnore As String = "")
          Dim f As Form
          For Each f In Forms
              If Not f Is Nothing Then
                  If f.Name &lt;&gt; FormToIgnore Then
                      Unload f
                      Set f = Nothing
                  End If
              End If
          Next f   
      End Sub
  
  '\code'  
  </code></pre>
  
  <p>6) I have added a "getout" routine in the start up module on the hope that will allow the form object to close cleanly this did not fix the issue<br>
  Thank you all so much for your help </p>