Microsoft KB Archive/99939

= ACC: How to Communicate with NetDDE =

Article ID: 99939

Article Last Modified on 5/9/2003

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition

-



This article was previously published under Q99939



SUMMARY
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article demonstrates how to use NetDDE to communicate with Microsoft Access on a remote computer. This article assumes that you are familiar with DDE communications on a local computer, and with the capabilities of Microsoft Access as a DDE server.

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 on Access Basic, please refer to the &quot;Introduction to Programming&quot; manual in Microsoft Access version 1.x, or the &quot;Building Applications&quot; manual, Chapter 3, &quot;Introducing Access Basic,&quot; in version 2.0.



MORE INFORMATION
In order to establish a link to a remote application, a DDE share must be created on the remote computer. A DDE share is a name that represents an application name, a topic, and any permissions for that topic. A DDE conversation can only occur with applications and topics assigned to share names on the remote computer. Note that a utility called Network DDE Share Manager (provided with the Windows for Workgroups Resource Kit) can be used to create and edit DDE share names.

How to Create the DDE Share
The following steps demonstrate how to create a DDE share for the Employees table in the sample database NWIND.MDB:


 * 1) Start the Network DDE Share Manager. On the Share menu, click New.
 * 2) Type &quot;Northwind Employees&quot; (without the quotation marks) in the Share Name box.
 * 3) Type &quot;MSACCESS.EXE&quot; (without the quotation marks) in the Application Name box and &quot;NWIND.MDB;TABLE Employees&quot; (without the quotation marks) in the Topic Name box. The password information is optional and can be left empty.
 * 4) On the File menu, click Save.

How to Communicate with the Remote Microsoft Access DDE Share
NOTE: Before running the following function, make sure that Microsoft Access is running on the remote computer and that the NWIND.MDB database is open.

Create the following procedure in a Microsoft Access module on your local computer:

NOTE: In the following sample code, an underscore (_) is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.

  Option Explicit Function GetRemoteEmployeeInfo

Dim iChan As Integer Dim EmpRecord As String, FieldNames As String

iChan = DDEInitiate(&quot;\\RemoteMachineName\NDDE$&quot;, _     &quot;Northwind Employees&quot;)

FieldNames = DDERequest(iChan, &quot;FieldNames&quot;) MsgBox FieldNames, 0, &quot;Employee Table Field Names&quot;

On Error Resume Next EmpRecord = DDERequest(iChan, &quot;FirstRow&quot;) Do Until EmpRecord = &quot;&quot; MsgBox EmpRecord, 0, &quot;Employee Record&quot; EmpRecord = &quot;&quot; EmpRecord = DDERequest(iChan, &quot;NextRow&quot;) Loop

End Function

Change the first argument of the DDEInitiate command (RemoteMachineName) to reference the name of your remote computer.

When you run this function from the Immediate window, a message box will be displayed that shows a list of field names in the Employees table. Next, a series of message boxes will appear displaying each record from the table. The field data will be delimited by a tab character.

The DDEInitiate Statement
Note the arguments used in the DDEInitiate command to establish the link with the remote share. The application name is the net DDE server application NDDE$ located on the remote computer &quot;\\RemoteMachineName&quot;. NDDE$ is a system service application that is run automatically by Windows for Workgroups in the background. This application is always running and present when Windows for Workgroups is running and cannot be terminated.

When NDDE$ receives the topic &quot;Northwind Employees&quot; it checks the list of available DDE shares on the local computer. If it finds the share, it will validate any permissions on the share and prompt for a password if one is required. After the validation is complete, NDDE$ establishes a local DDE link with the application name and topic assigned to the share name.

Once the link has been established, communication with the client application proceeds as if it were another application on the local computer. NDDE$ becomes the liaison between the two applications across the network.

