Solved

microsoft access 2010 filtered data export

Posted on 2016-09-13
4
53 Views
Last Modified: 2016-09-16
do you know how to export filtered data export to excel?
0
Comment
Question by:Hiroyuki Tamura
  • 2
4 Comments
 
LVL 25

Assisted Solution

by:-MAS
-MAS earned 250 total points
ID: 41795799
Create a query based on your requirement then export using the below code.

DoCmd.OutputTo acOutputQuery, "Query_name", acFormatXLS, outputFileName
2
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 250 total points
ID: 41796057
Are you talking about filtering a table/query in a datasheet view and then exporting that filtered row set to Excel?
1
 

Author Comment

by:Hiroyuki Tamura
ID: 41796136
>Are you talking about filtering a table/query in a datasheet view

Yes, that is correct.
0
 
LVL 45

Accepted Solution

by:
aikimark earned 250 total points
ID: 41796220
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

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question