XL: DDEREQUEST May Truncate Results

Last reviewed: February 27, 1998
Article ID: Q151278
The information in this article applies to:
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for Windows 95, version 7.0
  • Microsoft Excel 97 for Windows
  • Microsoft Query for Windows, version 1.0
  • Microsoft Query for Windows 95, version 2.0
  • Microsoft Query 97 for Windows

SYMPTOMS

If you use DDERequest to retrieve the Structured Query Language (SQL) statement (QueryDefinition function) or the Open Database Connectivity (ODBC) SQL Statement (ODBCSQLStatement function) from Microsoft Query, the results may be truncated.

Sample statements that can produce this condition are as follows:

   DDERequest(<channel>, "QueryDefinition")

   DDERequest(<channel>, "ODBCSQLStatement")

where <channel> is the dynamic data exchange (DDE) to Microsoft Query channel variable.

WORKAROUND

You can avoid the truncation by using the following array form of these functions:

   DDERequest(<channel>, "QueryDefinition/n")

   DDERequest(<channel>, "ODBCSQLStatement/n")

where <channel> is the DDE to Microsoft Query channel variable,

The array form of these functions parses the SQL statement into array elements. You can use the following Visual Basic for Applications code sample to place the SQL statement on a worksheet using the array form of these functions.

Sample Visual Basic Code

Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

Before you run this subroutine, be sure that Microsoft Query 2.0 is open and you understand how to select a data source and return data to Microsoft Excel. If you have any questions regarding this topic, please see "Getting Started with Microsoft Office for Windows 95" and Microsoft Query Help.

Type the following code in a module sheet:

   Sub TestArrayQueryDefinition()

   '   Activate a worksheet.
   Worksheets(1).Activate
   '   Initiate a Channel to MSQuery.
   Chan = DDEInitiate("MSQUERY", "System")

   '   Give the user control in Microsoft Query so they can select data
   '   from a database and return to Excel.
   DDEExecute Chan, "[UserControl('&Return to Excel',3,true)]"
   '   At this point the code opens Microsoft Query and waits
   '   for the user to select a Data Source, Data Table(s), and data to
   '   return to Microsoft Excel.

   '   To request the Query Definition be parsed into of 50 character
   '   sections...
   QryDefArray = DDERequest(Chan, "QueryDefinition/50")
   '   To format the parsed Query Definition data...
   ArrayLen = UBound(QryDefArray, 1)
   Range("A1").Value = "Query Definition (renamed Column Names) in " _
      & ArrayLen & " parts:"
   '   If the Array length is one then a one dimension array is returned,
   '   if the Array length is greater than one, a two dimension array is
   '   returned.
   If ArrayLen = 1 Then
   '   Place the single line of data on the worksheet and remove wrap text.
      Range("A2") = QryDefArray(1): Range("A2").WrapText = False
   Else
   '   Place the parsed lines of data on the worksheet and remove wrap
   '   text.
      For i = 1 To ArrayLen
         Range("A" & i) = QryDefArray(i, 1)
         Range("A" & i).WrapText = False 'To undo wrap text
      Next i
   End If

   End Sub


Additional query words: XL5 XL7 XL97 5.00 5.00c 7.00 8.00 97
Keywords : kbprg xlquery
Version : WINDOWS:5.0,5.0c,7.0,97
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 27, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.