ACC2000: How to Use the Quit Method to Quit Access from Another Program (210518)



The information in this article applies to:

  • Microsoft Excel 2000
  • Microsoft Access 2000

This article was previously published under Q210518
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

SUMMARY

This article describes how to close Microsoft Access from a different program using Automation and the Quit method.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. To close Microsoft Access from Microsoft Excel, follow these steps:
  1. Start Microsoft Access and open any database.
  2. Start Microsoft Excel, point to Macro on the Tools menu, and then click Visual Basic Editor.
  3. On the Insert menu, click Module.
  4. Type the following Sub procedure:
    Sub OleAccess()
       Dim appAccess as Object
       Set appAccess = GetObject(, "Access.Application")
       appAccess.Quit acSave
    End Sub
    					
  5. To run this code, click Run Sub/UserForm on the Run menu, or call the Sub procedure from another procedure.

    When it runs, the GetObject() function sets the appAccess variable to the first available open instance of Microsoft Access. At the end, it closes Microsoft Access with appAccess.Quit.
NOTE: If you do not have Microsoft Access running in the background when you run the procedure, you receive a run-time error. You can trap for this error by using On Error.

REFERENCES

For more information about the Quit method, click Microsoft Visual Basic Help on the Help menu, type Quit method in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

Modification Type:MajorLast Reviewed:6/23/2005
Keywords:kbhowto kbinterop KB210518