ACC: Running a MS Access Macro from Visual Basic Using DDE

Last reviewed: August 29, 1997
Article ID: Q97776
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0, 97
  • Microsoft Visual Basic version 3.0

SUMMARY

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

The following example uses Microsoft Visual Basic 3.0 to run macros in Microsoft Access using dynamic data exchange.

MORE INFORMATION

The following code demonstrates how to run a macro called "MyMacro" in Microsoft Access from a Visual Basic application.

   Sub Command1_Click()
      ' The character between MSACCESS and System is the pipe symbol.
      Text1.LinkTopic = "MSACCESS|System"

      ' Establish a manual DDE link to Microsoft Access.
      Text1.LinkMode = 2

      ' Run the macro called "MyMacro"
      Text1.LinkExecute "MyMacro"

      ' Terminate the DDE link to Microsoft Access.
      Text1.LinkMode = 0
   End Sub

To use this code, create a new Visual Basic program with a text box and a command button with the following properties:

   Text box
   --------
   Name: Text1

   Command Button
   --------------
   Name: Command1

Double-click the command button and enter the code example listed above between the "Sub Command1_Click ()" and "End Sub" lines.

When you run this example, be sure that Microsoft Access is running and that a database containing a macro called "MyMacro" is open. For testing purposes, you may want to create a macro called "MyMacro" that contains a single MsgBox action.

NOTE: While the above example uses the Microsoft Access system Topic listed in the LinkTopic line, Microsoft Access is capable of running a macro with virtually every valid topic it supports. For a list of topics that Microsoft Access supports, please see the following article here in the Microsoft Knowledge Base:

  ARTICLE-ID: Q96845
  TITLE:      How to Use DDE to Display Microsoft Access Data in VB 3.0
Keywords          : IntpDde kbinterop PgmHowTo
Version           : 1.0 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.