ACC: Problems Quitting Microsoft Access

Last reviewed: August 29, 1997
Article ID: Q164455
The information in this article applies to:
  • Microsoft Access versions 7.0, 97

SYMPTOMS

Moderate: Requires basic macro, coding, and interoperability skills.

When you click Exit on the File menu in Microsoft Access, the program does not quit.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

CAUSE

There are two possible causes for this problem:

  • You are using Microsoft Access as an automation server, and you have not closed all references to Microsoft Access or Data Access Objects (DAO).
  • You have not explicitly closed all DAO recordsets or query definitions in your Microsoft Access database. If you are using Visual Basic for Applications code to manipulate recordsets, QueryDefs, or recordset clones (on forms), in some cases you must explicitly close the object; otherwise, Microsoft Access does not close.

RESOLUTION

When you use Microsoft Access as an automation server, invoke the Quit method to explicitly close the Microsoft Access object when you are finished with it in your code, and then set its object variable equal to Nothing, for example:

   Sub CloseAccess()
      Dim objAccess As Object
      Set objAccess = CreateObject("Access.Application")
      objAccess.Visible = True
      Msgbox "Microsoft Access is open; this procedure will now close it."
      objAccess.Quit
      Set objAccess = Nothing
   End Sub

When you create Recordset or QueryDef objects in code, explicitly close the object when you are finished with it. Microsoft Access automatically closes those types of objects under most circumstances; however, if you explicitly close the object in your code, you can avoid occasional instances when the object remains open. The following sample code opens and closes a Recordset and a QueryDef object in the Northwind sample database:

   Sub CloseObjects()
      Dim db As Database
      Dim rs As Recordset
      Dim qd As QueryDef

      Set db = CurrentDb
      Set rs = db.OpenRecordset("Employees", dbOpenTable)
      Set qd = db.QueryDefs("Invoices")

      rs.MoveLast
      MsgBox "The Employees recordset is open." & vbcr & _
         "The last Employee ID is " & rs![EmployeeID] & "."

      Msgbox "The Invoices query definition is open." & vbcr & _
         "The first field in the query is " & qd.Fields(0).Name

      ' Explicitly close the Recordset and QueryDef objects.
      rs.Close
      qd.Close
   End Sub

MORE INFORMATION

Steps to Reproduce Behavior

The following example uses automation to open a second instance of Microsoft Access that will not close:

  1. Start Microsoft Access and open the sample database Northwind.mdb.

  2. Create a module and type the following line in the Declarations section:

          Dim objAccess As Object
    

  3. Type the following procedure:

          Sub LeaveOpen()
             Set objAccess = CreateObject("Access.Application")
             objAccess.Visible = True
          End Sub
    
    

  4. To test this function, type the following line in the Debug window, and then press ENTER.

           LeaveOpen
    

  5. When another instance of Microsoft Access starts, switch to that instance.

  6. On the File menu, click Exit. Note that the new instance of Microsoft Access minimizes, but does not quit. You must switch back to the first instance of Microsoft Access and close the database. Then the second instance quits automatically because its object variable ceases to exist.

REFERENCES

For more information about using Microsoft Access as an automation server, search the Help Index for "Automation," and please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q147816
   TITLE     : ACC: Using Microsoft Access as an Automation Server

   ARTICLE-ID: Q145707
   TITLE     : ACC: Using Automation to Print Microsoft Access Reports


Additional query words: close down quit stop exit OLE
Keywords : AutoGnrl JetRS kbusage IntpOleA MdlDao
Version : 7.00 97
Platform : WINDOWS
Hardware : x86
Issue type : kbprb
Solution Type : Info_Provided


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.