ADT: How to Direct DDE to a Specific Instance of a ServerLast reviewed: April 7, 1997Article ID: Q105659 |
The information in this article applies to:
SUMMARYAdvanced: Requires expert coding, interoperability, and multiuser skills. You can run multiple instances of the same application under Microsoft Windows. When you communicate with an application using DDE, it may be important to be able to identify which instance of an application should respond to your DDE commands. You can initiate a DDE conversation with a specific instance of an application by appending the application's Task ID number to the application name argument in the DDE initiate command. This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x, or the "Building Applications" manual, Chapter 3, "Introducing Access Basic" in version 2.0.
MORE INFORMATIONEach instance of each application started in Windows is assigned a unique number called a Task ID. This number can be used to distinguish among multiple instances of an application. To initiate a DDE conversation using the System topic with an instance of Microsoft Excel that has a Task ID of 34567, you could use the following sample command:
Chan = DDEInitiate("excel34567", "System")If you do not specify a Task ID number, you will initiate a conversation with the first instance of the application that Windows finds. Note that the order in which Windows finds instances of an application does not always correspond to the order in which the applications were started.
How to Get the Task ID of an ApplicationYou can get the Task ID of an application by doing one of the following:
Notes
Function TestTaskID() Dim TaskID TaskID = Shell("excel", 1) MsgBox TaskID & " and " & GetActiveTaskID() End Function How to Use an Application's Task ID in a DDE ConversationThe following example demonstrates how to use Task IDs to indicate which instance of an application should be used in a DDE conversation. This sample code will launch two instances of Microsoft Excel, start a DDE conversation with each instance, and poke data to Sheet1 of each instance:
Function DDEWithTwoInstances () Dim TaskID1, TaskID2 Dim Chan1, Chan2 ' Start 2 instances of Microsoft Excel and record Task ID numbers. TaskID1 = Shell("excel.exe", 1) TaskID2 = Shell("excel.exe", 1) ' Initiate DDE conversations with both instances using ' the Task ID numbers. Trap an error that may happen ' if we try to initiate a conversation and the copy of ' Microsoft Excel is still trying to start from the shell command. On Error GoTo ExcelNotYetReady Chan1 = DDEInitiate("excel" & TaskID1, "Sheet1") On Error GoTo 0 On Error GoTo ExcelNotYetReady Chan2 = DDEInitiate("excel" & TaskID2, "Sheet1") On Error GoTo 0 ' Poke information into each instance of Microsoft Excel. DDEPoke Chan1, "R1C1", "This is Task1!" DDEPoke Chan2, "R1C1", "This is Task2!" DDETerminateAll Exit Function ExcelNotYetReady: DoEvents Resume End Function REFERENCESMicrosoft Access "Introduction to Programming," version 1.1, pages 139-147
|
Additional query words: dynamic data exchange adk
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |