The information in this article applies to:
SUMMARYIn earlier versions of Microsoft Excel, you can use SQLBIND to specify where the results of a query are placed. However, if you use Data Access Objects (DAO), and you use the CopyFromRecordset method, data is always returned to a contiguous section of the worksheet. SQLBIND is not available with DAO; therefore, you must use alternate method of placing data in specified columns when you use DAO. This article demonstrates how to do this. MORE INFORMATIONMicrosoft 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.aspIn order to specify into which columns the results of a data retrieval are inserted, it is necessary to loop through the recordset, specifying into which cells to place the data in each iteration of the loop. The following subroutine will retrieve the Customers table in the Northwind database. The subroutine will then place the CustomerID field in Column A, the CompanyName field in Column C, and the ContactName field in Column E of Sheet1. The data is placed in the worksheet starting on the second row so that field headers can be placed in the first row. NOTE: This subroutine is designed to run using the Northwind database that is included with both Microsoft Office 97 for Windows, Professional Edition and Microsoft Office version 7.0, Professional Edition. In Microsoft Office 97 for Windows, Professional Edition, the default location for the Northwind database is:
In Microsoft Office version 7.0, Professional Edition, the default
location for the Northwind database is:
If you installed the Northwind database in a different location, modify
the OpenDatabase statement in the following subroutine. Change the line
to point to the location of the Northwind database.
NOTE: If an error appears when you run this subroutine, make sure that
you referenced the DAO Object Library. To reference the library in
Microsoft Excel 97, click References on the Tools menu in the Visual
Basic Editor, and select "Microsoft DAO 3.5 Object Library." To reference
the library in Microsoft Excel version 7.0, activate the module sheet,
click References on the Tools menu, and select "Microsoft DAO 3.0 Object
Library."
REFERENCES
For more information about Data Access Objects in Microsoft Excel 97, from
the Visual Basic Editor, click the Office Assistant, type DAO, click
Search, and then click to view "Data Access Objects Overview."
Q176476 OFF: Office Assistant Not Answering Visual Basic QuestionsFor more information about data access objects in Microsoft Excel 7.0, click the Index tab in Microsoft Excel Help and type: DAO Additional query words: 8.00 97
Keywords : kbprg kbdta kbdtacode KbVBA |
Last Reviewed: November 9, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |