Can't Use SQLRetrieve/SQLRequest to Return Over 248 Columns

ID: Q136819


The information in this article applies to:
  • Microsoft Excel 97 for Windows
  • Microsoft Excel for Windows 95, version 7.0
  • Microsoft Excel for Windows, versions 5.0, 5.0a, 5.0c
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for the Macintosh, versions 5.0, 5.0a


SYMPTOMS

In Microsoft Excel, you can use the Xlodbc.xla add-in macro functions to return data from an external source to your worksheet. The XLODBC macro functions SQLRetrieve and SQLRequest may not behave as expected if you attempt to return more than 248 columns of data. If the SQLExecQuery function is used to create a query, this function will correctly return the number of columns in the data set resulting from the query even if this number exceeds 248.

In Microsoft Excel 5.0 for Windows, when you attempt to use SQLRetrieve or SQLRequest to return more than 248 columns of data, you may receive the error message:

Excel caused a General Protection Fault in module XLODBC.DLL at 0001:52E3
In Microsoft Excel 5.0 for Windows NT, Microsoft Excel 5.0 for the Macintosh, Microsoft Excel 7.0 for Windows 95 and Microsoft Excel 97, if you use SQLRetrieve or SQLRequest to return more than 248 columns of data, you will receive only the first 248 columns of the result set but you will not receive an error.


WORKAROUND

To work around this problem, use any of the following methods.

Method 1: Using Xlodbc.xla

You cannot return more than 248 columns of data to Microsoft Excel using the Xlodbc.xla macro functions unless you execute two separate queries--one query to return the first 248 columns and another query to return the remaining columns.
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/overview/overview.asp
Method 2: Using Xlquery.xla
You can use the Microsoft Query add-in to return more than 248 columns. The macro below demonstrates an example.

          Sub GetData()

          Dim ConStr As String
          Dim SQL As String

              'Open the Microsoft Query Add-in
              Workbooks.Open Application.LibraryPath & _
                 "\msquery\xlquery.xla"

              'Define the Connection String and the SQL Query
              ConStr = "DSN=NWind"
              SQL = "Select * from c:\windows\msapps\msquery\test.dbf"

              'Execute the query and return the data to cell A1 on
              'Sheet1--
              'Include the field names and do not store the query on
              'the worksheet
              Run "QueryGetData", ConStr, SQL, False, True, False, _
                  Sheets("Sheet1").Range("A1"), True

          End Sub 
Method 3: Using Data Access Objects (DAO) in Microsoft Excel 7.0 and 97
You can use DAO to return more than 248 columns. The macro below demonstrates an example. To use DAO in a Microsoft Excel 7.0 macro, click References on the Tools menu while the module sheet is active and select Microsoft DAO 3.0 Object Library.
To use DAO in a Microsoft Excel 97 macro, click References on the Tools menu in Visual Basic Editor and select Microsoft DAO 3.5 Object Library.

          Sub GetData()

          Dim db as Database
          Dim rs as Recordset

             'Open the dBASE database in the specified directory
             Set db = OpenDatabase("c:\windows\msapps\msquery", False,_
                   False, "dBASE IV;")

             'Create a recordset that contains all of the records in
             'the table Test.dbf
             Set rs = db.OpenRecordset("Select * from Test")

             'Copy the data in the recordset to Sheet1!A2
             Sheets("Sheet1").Range("A2").CopyFromRecordset rs

             'Return the field names in the recordset to row 1
             For I = 0 to rs.Fields.Count -1
                   Sheets("Sheet1").Cells(1,I +1) = rs.Fields(i).Name
               Next

          End Sub 


STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

Additional query words: 8.00 97 GP Fault GPF

Keywords : kbprg ODBCGen
Version : MACINTOSH:5.0,5.0a; WINDOWS:5.0,5.0a,5.0c,7.0,97; winnt:5.0
Platform : MACINTOSH WINDOWS winnt
Issue type : kbbug


Last Reviewed: November 9, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.