Article ID: 136819
Article Last Modified on 8/17/2005
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.
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
Additional query words: 8.00 97 GP GPF Excel caused a General Protection Fault in module XLODBC DLL XL
Keywords: kberrmsg kbbug kbprogramming kbpending KB136819