473,581 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exporting A Filtered Form To Excel

17 New Member
Here's one that's been bugging me for about a week now...

I have a form that allows users to filter records, simple enough. But I want to give them the option to export the filtered records to Excel. I don't want to use the docmd.outputTo due to it won't filter the records, it puts all of the records in the file. I've looked around and found some code (actually that I'm already using), but the problem is that it outputs EVERYTHING on the form. My goal is to output only the fields that are on the form.

I found another bit of code (following) that does what I need it to do in the way of only exporting the data and field names, but I've inadvertantly deleted part of one line (the Set rs=currentDB) and commented it out.

Expand|Select|Wrap|Line Numbers
  1. Dim xlApp As Object
  2. Dim xlBook As Object
  3. Dim rs As DAO.Recordset
  4. Dim sql As String
  5. Dim i As Integer
  7. Set xlApp = CreateObject("Excel.Application")
  8. Set xlBook = xlApp.Workbooks.Add
  10. sql = Forms("frmProjectEDISearch").Form.RecordSource 'Your record source if not a subform
  11. 'Set rs = CurrentDb.
  13. For i = 1 To rs.Fields.Count
  14. xlBook.Sheets(1).Cells(1, i) = rs.Fields(i - 1).Name 'Write Field names to Excel
  15. Next i
  16. xlBook.Sheets(1).Cells(2, 1).CopyFromRecordset rs 'Import the recordset data through Excel
  18. ' You can add whatever other formatting you want by running Excel VBA throught the xlApp object
  20. xlApp.Visible = True
  22. Set xlApp = Nothing
  23. Set xlBook = Nothing
  24. Set rs = Nothing
I know that the rs statement is for the Record Source. But...I'd like to somehow have that statment pull in the filtered data. Most everything I've seen with the OpenRecordset command uses a table or query. The filter is on the form and changes dynamically based on what's entered.

Any help would be greatly appreciated.


Nov 16 '07 #1
2 19292
1,923 Recognized Expert Top Contributor
it looks like you have already gotten your answer from allen browne.

Nov 18 '07 #2
2 New Member
try sending data to a temp table using your search query before exporting it to excel.
Nov 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works only exporting to single worksheet. but i need to export data to multiple worksheets. it is very urgent to us. so please help me in code.
by: WindAndWaves | last post by:
Dear Gurus I am trying to export some data to excel from a form, but I seem to run into difficulties when the user has filtered for particular data that is from a dropdown (linking to another table in a one to many relationship). The W (filter for the form) that caused the error was WHERE (((.DD="New York"))) AND ((.DD="X"))
by: Mike O. | last post by:
MS Access 2003 "filter by form" has drop down lists that allow the user to select values for each field to filter by. However, once some values are selected,the remaining dropdown lists remain the same and aren't progressively filtered to reflect the selections already made in other fields. This can be very tedious when filtering a large...
by: Michael | last post by:
I need to be able to export data from a web form into MS Excel. I know you can do it with a VB.net windows application, but how can you do it with an asp.net application using vb.net? Any help would be appreciated! Michael
by: ad | last post by:
I use the code below to export the content of a data set to Excel, the code come form http://www.dotnetjohn.com/articles.aspx?articleid=36 But it always use the web form's name as the default name of excel. Can we specify a meaningful filename before exporting to EXCEL? ...
by: Mustufa Baig | last post by:
I have an ASP.NET website where I am showing off crystal reports to users by exporting them to pdf format. Following is the code: ---------------- 1 Private Sub ExportReport() 2 Dim oStream As System.IO.MemoryStream = 3 myReport.ExportToStream( ExportFormatType.PortableDocFormat) 4 Response.Clear() 5 ...
by: Ken | last post by:
I have a form that has a command button on it to open a report. The report is based on the forms data, if it's filtered the report is filtered, if the form is showing 100 records the report is showing the same 100 records, etc. I want to create another command button which exports to excel, in the same manner above. Whether the form is...
by: jennwilson | last post by:
Access 2000 - I have developed a database that houses patient information. The patient information must be sent in an excel file to another company department. I know how to export my data to Excel where it ends up in individual cells (Rows/Colums, etc). I would like for the report that I am exporting to Excel to transfer like a pdf. file. and...
by: martin DH | last post by:
Hello, I've hit a mental roadblock and could use some design ideas if anyone is willing. Access 2003, Windows XP Pro In my database is a form (HOME) that is filled with command buttons that run queries and macros. For example, a button will ask the parameters of a query to produce filtered data and the macro runs to Export the data to an...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.