XL2000: DDEREQUEST May Truncate the Results of a Query (213794)



The information in this article applies to:

  • Microsoft Excel 2000
  • Microsoft Query

This article was previously published under Q213794

SYMPTOMS

If you use DDERequest to retrieve the 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 forms of these functions
  • DDERequest(channel, "QueryDefinition/n")

    -and-
  • 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.

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 a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site: For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:
Before you run this subroutine, be sure that Microsoft Query 2000 is open and that you understand how to select a data source and return data to Microsoft Excel.

For more information about using Microsoft Query, click Microsoft Excel Help on the Help menu, type microsoft query in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

Sample Visual Basic Code

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
				

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbbug kbpending kbProgramming KB213794