DDE Conversations

Two applications using DDE to exchange data are said to be involved in a DDE conversation. An application, like a television set, uses a channel to transmit information. But unlike a television set, a DDE channel can support conversations in which data flows in both directions.

Your Access Basic code can conduct more than one conversation with the same application at the same time, but each conversation occurs on a different channel. Your code can maintain many open channels simultaneously in addition to any Microsoft Access DDE links that exist outside of your code—in form expressions, for example.

The application that initiates a conversation is called the destination application, or DDE client, for that conversation. The application that responds to a DDE client is called the source application, or DDE server, for that conversation. Notice that Microsoft Access can initiate a conversation with an application on one channel and respond to another application on another channel. In this situation, Microsoft Access is the client for the first conversation and the server for the second conversation. For example, an Access Basic procedure might initiate a conversation with Microsoft Excel to pass sales data. In this case, Microsoft Access is the DDE client and Microsoft Excel is the server. Microsoft Access can also be a server for other applications.

Applications, Topics, and Items

To begin a DDE conversation, your code must specify two things:

The name of the server, or source application, to talk to.

The topic of the conversation.

When a server receives a request for a conversation about a topic it recognizes, it responds and opens a channel. Once established, a conversation can't change topics or applications. To begin a conversation with a different server or with the same server about a different topic, you must start a new conversation on a different channel. This doesn't affect the conversation on the first channel; you can either end the first conversation or continue it.

Once a conversation has begun, the two applications exchange messages concerning particular items. An item is usually a reference to a piece of data contained in the topic. Items can vary from topic to topic, and each server can recognize different topics.

Every Windows-based application that can participate in DDE conversations has a unique application name. The table below shows the application names for some Microsoft applications.

Application

Application name

Microsoft Access

MSAccess

Microsoft Excel

Excel

Word for Windows

WinWord


A topic defines the "subject" of the DDE conversation and represents some unit of data meaningful to the DDE server application. For most applications that operate on files, this is a filename. Some possible topics are a Microsoft Excel worksheet name, for example, "DAILYORD.XLS," or a Word document name, for example, "SALESREP.DOC." In Microsoft Access the name of a database can be a topic, for example, "NWIND.MDB." A special topic that most applications recognize is "System." You can use this topic to obtain information about the application, such as the other topics it supports. Generally, when a topic refers to a file, that file must be open for the DDE server to respond to a conversation initiated about that topic.

An item is a reference to a piece of data (such as a range of cells in a Microsoft Excel worksheet, a bookmark in a Word for Windows document, or a database server in a Microsoft Access database) that can be exchanged between two applications. An item refers to a specific piece of a topic.

Initiating a DDE Conversation

To initiate a DDE conversation with another application, use the DDEInitiate function:

DDEInitiate(appname, topic)

For example, to initiate a conversation with Microsoft Excel on the System topic:

ChannelNum = DDEInitiate("Excel", "System")

If DDEInitiate is successful in initiating a conversation with the specified application, it returns a number that refers to the open channel. You use this channel number as an argument in other DDE statements and functions, enabling you to maintain multiple conversations and perform different operations on each.

If the specified application isn't already running, or if the specified application is running but doesn't recognize the specified topic, an error that can be trapped occurs. You should add code to check to see if an application is running, and then to start it if it isn't.