Microsoft KB Archive/97776

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

Article ID: 97776

Article Last Modified on 1/18/2007

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q97776



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



SUMMARY
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 &quot;MyMacro&quot; in Microsoft Access from a Visual Basic application. Sub Command1_Click ' The character between MSACCESS and System is the pipe symbol. Text1.LinkTopic = &quot;MSACCESS|System&quot; ' Establish a manual DDE link to Microsoft Access. Text1.LinkMode = 2 ' Run the macro called &quot;MyMacro&quot; Text1.LinkExecute &quot;MyMacro&quot; ' 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 &quot;Sub Command1_Click &quot; and &quot;End Sub&quot; lines.

When you run this example, be sure that Microsoft Access is running and that a database containing a macro called &quot;MyMacro&quot; is open. For testing purposes, you may want to create a macro called &quot;MyMacro&quot; 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:

96845 How to Use DDE to Display Microsoft Access Data in VB 3.0

Keywords: kbhowto kbinterop kbprogramming KB97776

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.