ACC: How to Use the Quit Macro Action

Last reviewed: August 29, 1997
Article ID: Q100149
The information in this article applies to:
  • Microsoft Access versions 1.1, 2.0, 7.0, 97
  • Microsoft Excel version 4.0, 5.0, 7.0

SUMMARY

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article demonstrates two methods to close Microsoft Access from a different application. The first method uses the Quit macro action to quit Microsoft Access over a dynamic data exchange (DDE) channel. The second method uses Automation and the Quit method.

MORE INFORMATION

Dynamic Data Exchange method

The syntax for the Quit action is:

   Quit

There are no parameters for the Quit action.

The following example shows a Microsoft Excel version 4.0 macro to demonstrate the Quit macro action. The macro is valid for Microsoft Excel versions 4.0, 5.0, and 7.0 and Microsoft Excel 97.

NOTE: This macro will not work with Microsoft Access version 1.0.

  1. Open a new macro sheet in Microsoft Excel. On the Insert menu, click Macro, and then click MS Excel 4.0 Macro. Enter the following macro:

          Cell     Command
          ------------------------------------------------
          A1       QuitDDEExample
          A2
          A3       =APP.MINIMIZE()
          A4       =ERROR(FALSE)
          A5       =APP.ACTIVATE("Microsoft Access",FALSE)
          A6       chan=INITIATE("MSACCESS","system")
          A7       =APP.ACTIVATE("Microsoft Access",FALSE)
          A8       =EXECUTE(chan,"[QUIT]")
          A9       =TERMINATE(chan)
          A10      =APP.ACTIVATE(FALSE)
          A11      =RETURN()
    
    

  2. Before running this macro, size your Microsoft Access and Microsoft Excel windows so that you can view both applications at the same time.

  3. To run the macro, select cell A3. On the Tools menu, click Macro. In the Macro box, click Run.

Automation Method

This method is exclusive for Microsoft Access 7.0 and Microsoft Access 97. Earlier versions of Microsoft Access are not OLE Servers, and therefore you can't manipulate them using Automation.

  1. Open Microsoft Access.

  2. Open Microsoft Excel (or another OLE server) and create a new macro. On the Insert menu, click Macro, and then click Module. This will insert a new module in the current book.

  3. Type the following Sub procedure:

          Sub OleAccess()
             Dim appAccess as Object
             Set appAccess = GetObject(, "Access.Application")
             appAccess.Quit acSave
          End Sub
    
    

  4. To run this code, click Start on the Run menu, or call the Sub procedure from another procedure. When it runs, the GetObject() function is executed, setting the appAccess variable to the first available open instance of Microsoft Access. At the end, it closes Microsoft Access with appAccess.Quit.

Note that you will get a run-time error if you don't have Microsoft Access loaded in the background while you run the procedure. This error can be trapped using On Error.

REFERENCES

For more information about the Quit method, search the Help Index for "Quit method," or ask the Microsoft Access 97 Office Assistant.

For more information about using macro actions in DDE, please see the following article here in the Microsoft Knowledge Base:

   ARTICLE-ID: Q97776
   TITLE:      ACC: Running a MS Access Macro from Visual Basic Using DDE


Additional query words: ole/dde server
Keywords : AutoGnrl IntpDde kbinterop IntpOleA
Version : 1.1 2.0 7.0 97
Platform : WINDOWS
Hardware : x86
Issue type : kbhowto


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.