microsoft access 2010 filtered data export

do you know how to export filtered data export to excel?
Hiroyuki TamuraField EngineerAsked:
Who is Participating?
 
aikimarkConnect With a Mentor Commented:
Please try this.
Sub Q_28969428()
    Dim strSrc As String
    Dim strFilter As String
    Dim rs As Recordset
    Dim oXL As Object
    Dim oWkb As Object
    Dim rng As Object
    Dim fld As Field
    
    strSrc = Application.Screen.ActiveDatasheet.Recordset.Name
    strFilter = Application.Screen.ActiveDatasheet.Filter
    Set rs = DBEngine(0)(0).OpenRecordset("Select * From " & strSrc & " Where " & strFilter)
    Set oXL = CreateObject("Excel.Application")
    Set oWkb = oXL.Workbooks.Add
    oXL.Visible = True
    Set rng = oWkb.Worksheets("Sheet1").Range("A1")
    For Each fld In rs.Fields   'headers
        rng.Value = fld.Name
        Set rng = rng.Offset(0, 1)
    Next
    oWkb.Worksheets("Sheet1").Range("A2").CopyFromRecordset rs
End Sub

Open in new window

0
 
MAS (MVE)Connect With a Mentor Technical Department HeadCommented:
Create a query based on your requirement then export using the below code.

DoCmd.OutputTo acOutputQuery, "Query_name", acFormatXLS, outputFileName
2
 
aikimarkConnect With a Mentor Commented:
Are you talking about filtering a table/query in a datasheet view and then exporting that filtered row set to Excel?
1
 
Hiroyuki TamuraField EngineerAuthor Commented:
>Are you talking about filtering a table/query in a datasheet view

Yes, that is correct.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.