Microsoft KB Archive/105658

= ACC: "Syntax Error in String" Error Using DDE and DDESend =

Article ID: 105658

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition

-



This article was previously published under Q105658



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



SYMPTOMS
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: <pre class="fixed_text">     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 </li> 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.</li> 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.</li> 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."</li></ol>

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

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
<ol> Create a blank, unbound form.</li> Add a text box to the form.</li>  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")                   </li></ol>

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.

<div class="references_section">