Here's another example I found:
Private mobjXl As Excel.Application
Private Function ExportToExcel(strSQL as String)
Dim rst ADODB.Recordset
Dim intCount As Integer
' Create the Excel object
Set mobjXl = New Excel.Application
' Fetch the recordset
With rst
.ActiveConnection = CurrentProject.Connection.ConnectionString
.CursorLocation = adUseClient
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.MaxRecords = 65000 ' Approx max number of rows Excel can handle
.Open strSQL
End With
With mobjxl
' Add a workbook and turn of Excel updates
.ScreenUpdating = False
.Visible = False
.Workbooks.Add
.DisplayAlerts = False
' Add the column headers
For intCount = 0 To rst.Fields.COUNT - 1
.Cells(1, intCount + 1).Value = rst.Fields(intCount).Name
Next intCount
' Dump the recordset to Excel
.Range("A2").CopyFromRecordset rst
.Visible = True
End With
' Add your error handler
End Function
Bonnie
http://www.dataplus-svc.com
Sorry missed that. That's a little more complicated because you need to use
the recordset. Here's a link I found:
http://www.access-programmers.co.uk...pyfromrecordset
Bonnie
http://www.dataplus-svc.com
Hi bhicks11, well..what i want to do is to export the filtered records from a
certain form...
[quoted text clipped - 4 lines]