ACC: OpenDatabase and CloseDatabase Pseudo Actions

Last reviewed: June 3, 1997
Article ID: Q100148
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0, 97

SUMMARY

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

Microsoft Access includes two "pseudo actions," or dynamic data exchange (DDE) commands, called OpenDatabase and CloseDatabase. These commands are available through the DDE SYSTEM topic, and allow you to open and close Microsoft Access databases over a DDE channel.

MORE INFORMATION

The syntax for the OpenDatabase and CloseDatabase pseudo actions is

   OpenDatabase <Database_Location>

   CloseDatabase

where <Database_Location> is the path and filename of the Microsoft Access database to be opened. The CloseDatabase action does not take a parameter since Microsoft Access can have only one database open at a time.

The following sample Microsoft Excel macro demonstrates how the OpenDatabase and CloseDatabase pseudo actions work.

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

  1. Start Microsoft Access (Microsoft Access must already be running in order for this macro to work).

  2. In Microsoft Excel open a new Excel 4.0 macro sheet. Enter the following macro:

          Cell    Command
          -------------------------------------------------
    
          A1      PseudoOpenCloseDDEExample
          A2
          A3      chan=INITIATE("MSACCESS","SYSTEM")
          A4      =APP.ACTIVATE("Microsoft Access",FALSE)
          A5      =EXECUTE(chan,"[opendatabase northwind.mdb]")
    
          NOTE: In versions 1.1 and 2.0, use =EXECUTE(chan,"[opendatabase
          nwind.mdb]")
    
          A6      =EXECUTE(chan,"[Sample AutoExec]")
          A7      =EXECUTE(chan,"[closedatabase]")
          A8      =TERMINATE(chan)
          A9      =APP.ACTIVATE(,FALSE)
          A10     =RETURN()
    
    

  3. Select cell A3. On the Macro menu, click Run, and then click OK.

The commands in cells A3 and A4 initiate a DDE channel to Microsoft Access on the SYSTEM topic and activate the Microsoft Access application.

The command in cell A5 opens the sample database Northwind.mmdb (or NWIND.MDB in version 1.1 and 2.0) in the current working folder (directory), using the OpenDatabase pseudo action.

The command in cell A6 runs the "Sample AutoExec" macro in the Northwind.mdb.

The command in cell A7 closes the currently opened database file using the CloseDatabase pseudo action.

The commands in cells A8-A10 terminate the DDE channel, activate the Microsoft Excel application, and end the macro.

For more information about Using Microsoft Access as a DDE Server, search the Help Index for "servers, DDE," or ask the Microsoft Access 97 Office Assistant.


Additional query words: ole/dde server
Keywords : IntpDde kbinterop
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Hardware : X86
Issue type : kbinfo


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: June 3, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.