Export filtered data

kafedral

New Member
Joined
Apr 20, 2011
Messages
5
hello, i've looked around the site and found a way to export my queries to excel with this code:
Code:
  DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, "tblDepartments", "C:\Test1.xls", False

but i still want to filter my queries before i export them, ether that or i need to make a button that exports the filtered data in forms and reports just like the one in the "external data" menu.

Thank you for your help.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Is the filter for tblDepartments the same every time? If so, create it as a query and export the query in the same manner as you've coded to export the table.
Phil...
 
Upvote 0
@Phil
ye.. but that is not the case, in my case i have eight different filters for like twenty queries, and i cant leave the top panel visible.

so can anyone help me with this?
 
Upvote 0
Have you considered building a search form with unbound text boxes that contain your filter criteria? Use the text boxes as the criteria in your query to filter it. Then your results are filtered and can be exported with out any additional work. Here is a link on how to build a search form that will allow you or your users to filter your query.

http://www.datapigtechnologies.com/flashfiles/searchform.html

Alan
 
Upvote 0
I'm not sure this will help, but perhaps you should explore the Help files on the Filter() function.
Returns a zero-based array containing subset of a string array based on a specified filter criteria.
Syntax
Filter(sourcearray, match [, include ] [, compare ] )

Phil...
 
Upvote 0
@ Alan
I already have all my forms containing the data that i need but my problem is how to make a button that exports filtered data to excel and so far i found a way to do so using only my queries and tables.

@ Phil
Thanks a lot for your help that sounds like a great idea, I've looked up this function but I'm not so good with VBA so this is what i came up with
Code:
Private Sub Command17_Click()
    Dim xTarget As Variant
    xTarget = Filter("qryOrders", "Buy the Book")
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, xTarget, "C:\Test1.xls", False
    MsgBox ("Export Complete")
End Sub

and as expected it's not working... if anyone can help me with that it will be great.
 
Upvote 0
I'm confused with your statement
@ Alan
I already have all my forms containing the data that i need but my problem is how to make a button that exports filtered data to excel and so far i found a way to do so using only my queries and tables.

A form is a way to present data from an underlying Table or Query.
Whatever the Record source is for the Form, will be the "thing" (table or query) you would export.

Perhaps you could clarify exactly what the issue is.
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,334
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top