Export filtered data to Excel from a form based on a query

P

Peter

Hi all, I have been trying to export the filtered data from a form (based on
a query) to excel…well…and I am not Einstein so to say :)

Thanks again for your patience…..
 
P

Peter

Hi bhicks11, well..what i want to do is to export the filtered records from a
certain form...
 
B

bhicks11 via AccessMonster.com

B

bhicks11 via AccessMonster.com

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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top