XL: DDEREQUEST May Truncate Results

ID: Q151278

The information in this article applies to:

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

Microsoft provides programming examples 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. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/

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

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 kbdta xlquery KbVBA 
Version           : WINDOWS:5.0,5.0c,7.0,97
Platform          : WINDOWS

Last Reviewed: May 18, 1999