Using Microsoft Access As a DDE Server

Microsoft Access DDE as both a destination (client) application and a source (server) application. Although Microsoft Access doesn't support automatic linking, it manually updates linked data at specified intervals. The client application is notified when a change has occurred in a Microsoft Access database. The client application can then update the linked data. In most cases, this update occurs as fast as an automatic update. You can specify the interval between DDE link updates by setting the Refresh Interval option under the Multiuser/ODBC category in the Options dialog box (View menu). In the same dialog box under the General category, Enable DDE Refresh turns this feature on or off, and Ignore DDE Requests instructs Microsoft Access to ignore or accept DDE requests from other applications.

Each DDE conversation is established on a particular topic, usually a data file, with the conversation thereafter limited to the items associated with that topic. For example, if you are running Word for Windows and want to insert data from a particular Microsoft Access database into a Word for Windows document, you need to initiate a DDE conversation with Microsoft Access by opening a channel and specifying the database name as the topic. You can then use that channel to obtain data from the database.

The following example shows how to create a Word for Windows WordBasic macro that uses Microsoft Access as a DDE server. (For this example to work, Microsoft Access must either be running or be listed in the path command in your AUTOEXEC.BAT file.)


Sub MAIN
' Using the System topic, open the NWIND.MDB database. ' The database must be open before you can use other DDE topics. Chan1 = DDEInitiate("MSAccess", "System") DDEExecute Chan1, "[OpenDatabase C:\ACCESS\NWIND.MDB]" ' Get all the data from the Orders and Products query. Chan2 = DDEInitiate("MSAccess", "NWIND;QUERY Orders and Products") MyData$ = DDERequest$(Chan2, "All") DDETerminate Chan2 ' Close the database. DDEExecute Chan1, "[CloseDatabase]" DDETerminate Chan1 ' Insert the data into a text file. Open "MYDATA.TXT" For Append As #1 Print #1, MyData$ Close #1 End Sub

As a DDE server, Microsoft Access supports the following topics:

The System topic

The name of a database

The name of a table

The name of a query

A Microsoft Access SQL statement

The System Topic

The System topic is a standard topic for all Windows-based applications. It returns information about the topics supported by the application.

The System topic supports the following Microsoft Access items.

Item

Returns

SysItems

A list of items supported by the System topic in Microsoft Access.

Formats

A list of the formats Microsoft Access can copy onto the Clipboard.

Status

"Busy" or "Ready."

Topics

The System topic and a list of the full paths of all open Microsoft Access databases.


The database Topic

The database topic is the filename of an existing Microsoft Access database. You can specify just the base name, as in the NWIND database, or its full path and .MDB extension, as in C:\ACCESS\NWIND.MDB. After you initiate a DDE conversation with the database, you can request a list of the objects in that database.

The database topic supports the following items.

Item

Returns

TableList

A list of table names.

QueryList

A list of query names.

FormList

A list of form names.

ReportList

A list of report names.

MacroList

A list of macro names.

ModuleList

A list of module names.


The TABLE tablename, QUERY queryname, and SQL sqlstring Topics

These topics use the following syntax:

databasename;TABLE tablename

databasename;QUERY queryname

databasename;SQL [sqlstring]

Argument

Description

databasename

The name of the database that the table or query belongs to or that the SQL statement applies to, followed by a semicolon (;). The database name can be just the base name (NWIND) or its full path and .MDB extension (C:\ACCESS\NWIND.MDB).

tablename

The name of an existing table.

queryname

The name of an existing query.

sqlstring

A valid SQL statement up to 255 characters long, ending with a semicolon. To exchange more than 255 characters, omit this argument and instead use successive DDEPoke statements to build an SQL statement.


The following table lists the valid items for the TABLE tablename, QUERY queryname, and SQL sqlstring topics.

Item

Returns

All

All the data in the table, including field names.

Data

All rows of data, without field names.

FieldNames

A single-row list of field names.

FieldNames;T

A two-row list of field names (first row) and their data types (second row).

These are the values returned and the data types they represent:

0—Invalid

1—True/False (non-Null)

2—Unsigned byte (Byte)

3—2-byte signed integer (Integer)

4—4-byte signed integer (Long)

5—8-byte signed integer (Currency)

6—4-byte single-precision floating-point (Single)

7—8-byte double-precision floating-point (Double)

8—Date/Time (integral date, fractional time)

9—Binary data, 255 bytes maximum

10—ANSI text, not case-sensitive, 255 bytes maximum (Text)

11—Long binary (OLE Object)

12—Long text (Memo)


Item

Returns

NextRow

The data in the next row in a table or query. When you first open a channel, NextRow returns the data in the first row. If the current row is the last record and you request NextRow, the request fails.

PrevRow

The data in the previous row in a table or query. If PrevRow is the first request on a new channel, the data in the last row of the table or query is returned. If the first record is the current row, the request for PrevRow fails.

FirstRow

The data in the first row of a table or query.

LastRow

The data in the last row of a table or query.

FieldCount

The number of fields in a table or query.

SQLText

An SQL statement representing a table or query. For tables, this item returns an SQL statement in the form "SELECT * FROM tablename;"

SQLText;n

An SQL statement, in n-character chunks, representing a table or query, where n is an integer up to 255.