How to Perform Microsoft Access Macro Action Via DDE from VB 3.0

Last reviewed: July 20, 1995
Article ID: Q112767
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, version 3.0

SUMMARY

From Visual Basic, you cannot directly use a form or report that was created by the Microsoft Access engine. This article shows by example how to use DDE to do it indirectly. The example prints one of the built-in reports from the NWIND.MDB sample database by using DDE and the OpenReport macro action in Microsoft Access.

MORE INFORMATION

For more information about Microsoft Access macro actions, please see the Microsoft Access documentation or Help menu. A Visual Basic application can call most of these actions by using DDE.

Step-by-Step Example

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Add a text box (Text1) and Command button (Command1) to Form1.

  3. Place the following code in the Command1 button's click event:

       ' Note the time-out has to be long enough to allow for the print
       ' to complete or an error will occur.
       Sub Command1_Click ()
          Text1.LinkTimeout = 600 'Set DDE Time-out for 60 Seconds
          Text1.LinkTopic = "MSACCESS|SYSTEM"
          Text1.LinkMode = 2  ' Establish manual DDE link to Microsoft Access.
          Text1.LinkExecute "[OPENREPORT Catalog]" 'Open and Print     Report
          'Uncomment the next line to show a report with a where clause
          'Text1.LinkExecute "[OpenReport Freight Charges,,, [Order ID]=10506]"
          Text1.LinkMode = 0  ' Terminate the DDE link to Microsoft Access
       End Sub
    
       Please note that for Microsoft Access version 1.1, the link topic needs
       to be ACCESS|SYSTEM.
    
    

  4. Start Microsoft Access and open the NWIND.MDB sample database.

    NOTE: It is very important that the database NOT be opened for Exclusive access. If this is done, the example will fail and an error 282 ("No foreign application has responded...") will be generated. Exclusive can be inherited from a previous open if multiuser is not explicitly specified.

  5. Run the Visual Basic program, and click the Command1 button.


Additional reference words: 3.00
KBCategory: kbinterop kbprg kbcode
KBSubcategory: IAPDDE APrgDataAcc


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: July 20, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.