Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CopyFromRecordSet

Status
Not open for further replies.

nath

Programmer
Dec 5, 2001
109
ES
Hello,

Does anyone know if there is a similar command to use with ADO for copying entire recordsets into a worksheet. The CopyFromRecordSet command (DAO command) doesn't work with ADO.

Thanks for your help,

Nath
 
It's not ADO that has the CopyFromRecordset method, its Excel:

Dim conn As New ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQl as String

strSQL = "Select * from tblSomeTable"
conn.CursorLocation = adUseClient
Set rs = conn.Execute(strSQL)

'Create a new workbook in Excel
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add
Set oSheet = oBook.Worksheets(1)

'Transfer the data to Excel
oSheet.Range("A1").CopyFromRecordset rs

'Save the Workbook and Quit Excel
oBook.SaveAs "C:\Book1.xls"
oExcel.Quit

'Close the connection
rs.Close
conn.Close



Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top