Microsoft KB Archive/100149

= ACC: How to Use the Quit Macro Action or Quit Method =

Article ID: 100149

Article Last Modified on 1/18/2007

-

APPLIES TO


 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition
 * Microsoft Excel 2000 Standard Edition
 * Microsoft Excel 2000 Service Pack 1
 * Microsoft Excel 2000 Standard Edition

-



This article was previously published under Q100149



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



SUMMARY
This article demonstrates two methods that you can use 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.



Dynamic Data Exchange method
The syntax for the Quit action is: Quit There are no parameters for the Quit action.

The following example uses 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, 7.0, and 97. NOTE: This macro will not work with Microsoft Access version 1.0.

  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  Before running this macro, size your Microsoft Access and Microsoft Excel windows so that you can view both applications at the same time. 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 to Microsoft Access 7.0 and 97. Earlier versions of Microsoft Access are not OLE Servers, and therefore you can't manipulate them by using Automation.  Open Microsoft Access. 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.</li>  Type the following Sub procedure: Sub OleAccess Dim appAccess as Object Set appAccess = GetObject(, "Access.Application") appAccess.Quit acSave End Sub </li> 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.</li></ol>

Note that you will get a run-time error if you don't have Microsoft Access loaded in the background when you run the procedure. You can trap for this error by using On Error.

<div class="references_section">