ACC: "Syntax Error in String" Error Using DDE() and DDESend()
ID: Q105658
|
The information in this article applies to:
-
Microsoft Access versions 2.0, 7.0
SYMPTOMS
Advanced: Requires expert coding, interoperability, and multiuser skills.
When you enter either the DDE() or the DDESend() function in the
ControlSource property of a text box on a form, you may receive the
following error message.
In Microsoft Access for Windows 95 version 7.0:
The expression you entered has an invalid string
In Microsoft Access version 2.0:
Syntax error in string
This article assumes that you are familiar with Visual Basic for
Applications and with creating Microsoft Access applications using the
programming tools provided with Microsoft Access. For more information
about Visual Basic for Applications, please refer to the "Building
Applications With Microsoft Access For Windows 95" manual.
NOTE: Visual Basic for Applications (used in Microsoft Access for Windows
95 version 7.0) is called Access Basic in version 2.0. For more information
about Access Basic, please refer to the "Building Applications" manual.
CAUSE
A reference to another control is being used for the application or topic
argument in the function. Note that you can successfully include a control
reference for the item or data argument.
RESOLUTION
The following example demonstrates how to create and use the sample Visual
Basic for Applications or Access Basic functions newDDE() and newDDESend()
in place of the DDE() and DDESend() functions:
- Open a module and enter the following code:
Option Explicit
Function newDDE (App, Topic, Item)
Dim chan
On Error GoTo ErrnewDDE
chan = DDEInitiate(App, Topic)
newDDE = DDERequest(chan, Item)
DDETerminate chan
ByenewDDE:
Exit Function
ErrnewDDE:
newDDE = "#DDEERROR"
Resume ByenewDDE
End Function
Function newDDESend (App, Topic, Item, DataToSend)
Dim chan
On Error GoTo ErrnewDDESend
chan = DDEInitiate(App, Topic)
DDEPoke chan, Item, DataToSend
DDETerminate chan
newDDESend = True
ByenewDDESend:
Exit Function
ErrnewDDESend:
newDDESend = False
Resume ByenewDDESend
End Function
- Start Microsoft Word for Windows, version 7.0. Save a new document
as Test.
- Type a few lines of text in the document, and then select the text.
- Click Bookmark on the Edit menu. Type MyBookMark, and then press ENTER.
- Switch to Microsoft Access (leave Word for Windows running).
- Create a new form with the following controls and properties:
Text box:
Name: App
Text box:
Name: Topic
Text box:
Name: Item
Text box:
Name: Data
Text box:
Name: DDE
ControlSource: =newDDE([App],[Topic],[Item])
Text box:
Name: DDESend
ControlSource:
=newDDESend([App],[Topic],[Item],[Data])
Format: True/False
- On the View menu, click Form. Note that "#DDEError" appears in the DDE text box, and "False" appears in the DDESend text box. These messages
occur because there are not yet valid application, topic, and item
arguments.
- Create the following entries:
App: Winword
Topic: Test
Item: MyBookMark
Data: Hello!
Note that the DDESend box displays "True," and the text "Hello!" appears
in the Word for Windows document.
- With the insertion point in the DDE box, press F9 to force the function to refresh. Note that "Hello!" appears in the DDE box in place of
"#DDEError."
STATUS
This behavior is by design.
MORE INFORMATION
When the form is opened, Microsoft Access immediately establishes a DDE
channel to the other application. This link uses the application and topic
arguments in the function. The channel is kept open until the form is
closed. Because the channel is open, the arguments necessary for opening
the channel cannot be altered.
Microsoft Access does not open a new channel whenever it needs to call or
refresh the control with the DDE() or DDESend() function. Doing so would
impose significant overhead and could result in performance degradation.
Steps to Reproduce Behavior
- Create a blank, unbound form.
- Add a text box to the form.
- Enter any of the following expressions in the text box's ControlSource property:
=DDE("winword",[topic],"my item")
=DDE([app],"MyDoc","my item")
=DDESend("winword",[topic],"my item, "my data")
=DDESend([app],"MyDoc","my item, "my data")
Note that you receive the error message mentioned earlier in this article.
Any reference to another control in the application or topic argument will
generate this error.
REFERENCES
For more information about sharing data between applications, search for
"dynamic data exchange (DDE)," and then "Overview" using the Microsoft
Access for Windows 95 Help Index.
Microsoft Access "User's Guide", version 2.0, pages 735, 740
Microsoft Access "Building Applications", version 2.0, pages 295-298
Additional query words:
Keywords : kbdta AccCon
Version : WINDOWS:2.0,7.0
Platform : WINDOWS
Issue type :