Microsoft KB Archive/104682

{|
 * width="100%"|

ACC1x: Cannot Paste Data from Clipboard Using DDE

 * }

Q104682

-

The information in this article applies to:


 * Microsoft Access versions 1.0, 1.1

-

SYMPTOMS
When you attempt to paste data into a dynamic data exchange (DDE) server application from Microsoft Access, the process does not complete correctly and the following error message is generated:

The other application won't perform the DDE method or operation you attempted.

If you are using Microsoft Word for Windows as your DDE server application, the error message "WordBASIC Err=102 Command failed" will appear in Word for Windows.

If you are using Microsoft Excel as your DDE server application, the error message "Cannot paste data" will appear in Microsoft Excel.

CAUSE
Microsoft Access does not "render," or place, the data on the Clipboard until an application requests the data for pasting. (This technique provides improved performance with large pieces of data.) When Microsoft Access issues the DDEExecute command to tell the DDE server application to paste the data, it waits for that command to finish before allowing any other operation to take place. When the DDE server application receives the paste command, it requests that Microsoft Access place the data on the Clipboard. However, Microsoft Access will not do this because it is waiting for the DDEExecute command to finish.

RESOLUTION
The following sample Access Basic function called RenderClipboard can be called to force Microsoft Access to render the data to the Clipboard before issuing the DDEExecute command:

NOTE: 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 "Introduction to Programming" manual.

NOTE: You may have some Microsoft Windows API functions defined in an existing Microsoft Access library; therefore, your declarations may be duplicates. If you receive a duplicate procedure name error message, remove or comment out the declarations statement in your code.

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

  '********************************************************* ' MODULE DECLARATION SECTION '*********************************************************  Declare Function OpenClipboard% Lib "User" (ByVal hWnd%) Declare Function GetClipboardData% Lib "User" (ByVal wFormat%) Declare Function CloseClipboard% Lib "User"

Global Const CF_TEXT = 1

Function RenderClipboard Dim RetVal As Integer RetVal = OpenClipboard(0) RetVal = GetClipboardData(CF_TEXT) RetVal = CloseClipboard End Function

The following example demonstrates how to use the RenderClipboard function:

 Start Microsoft Word for Windows. The default document Document1 should be open. Start Microsoft Access. Open the sample database NWIND.MDB.  Create a new module, and enter the following Access Basic function:

     Function CopyRecordToWinword Dim RetVal, Chan

' Copy the current record to the clipboard DoCmd DoMenuItem A_FORMBAR, A_EDITMENU, A_SELECTRECORD DoCmd DoMenuItem A_FORMBAR, A_EDITMENU, A_COPY

RetVal = RenderClipboard

Chan = DDEInitiate("winword", "Document1") DDEExecute Chan, "[EditPaste]" DDETerminate Chan End Function   Open the Customers form in Design view and add a command button with the following properties:

     Caption: Copy to Record OnPush: =CopyRecordToWinword  Change to Form view, and choose the Copy To Winword button. The record will be pasted into the Word for Windows document.

STATUS
Microsoft has confirmed this to be a problem in Microsoft Access versions 1.0 and 1.1. This problem no longer occurs in Microsoft Access version 2.0.

Steps to Reproduce Behavior
 Start Microsoft Word for Windows. The default document Document1 should be open.</li> Start Microsoft Access. Open the sample database NWIND.MDB.</li>  Create a new module, and enter the following Access Basic function:

Option Explicit

<pre class="CODESAMP">     Function CopyRecordToWinword Dim RetVal, Chan

' Copy the current record to the clipboard DoCmd DoMenuItem A_FORMBAR, A_EDITMENU, A_SELECTRECORD DoCmd DoMenuItem A_FORMBAR, A_EDITMENU, A_COPY

Chan = DDEInitiate("winword", "Document1") DDEExecute Chan, "[EditPaste]" DDETerminate Chan End Function </li>  Open the Customers form in Design view and add a command button with the following properties:

<pre class="FIXEDTEXT">     Caption: Copy to Record OnPush: =CopyRecordToWinword </li>  Change to Form view, and choose the Copy To Winword button. Word for Windows will generate the error message: "WordBASIC Err=102 Command failed."

NOTE: To reproduce the problem with Microsoft Excel, use the following Access Basic function instead of the function listed above:

Option Explicit

<pre class="CODESAMP">  Function CopyRecordToExcel Dim RetVal, Chan

' Copy the current record to the clipboard DoCmd DoMenuItem A_FORMBAR, A_EDITMENU, A_SELECTRECORD DoCmd DoMenuItem A_FORMBAR, A_EDITMENU, A_COPY

Chan = DDEInitiate("Excel", "Sheet1") DDEExecute Chan, "[Paste]" DDETerminate Chan End Function </li></ol>

Keywords : kbinterop

Issue type : kbbug

Technology :