473,386 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Exporting A Filtered Form To Excel

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
  6.  
  7. Set xlApp = CreateObject("Excel.Application")
  8. Set xlBook = xlApp.Workbooks.Add
  9.  
  10. sql = Forms("frmProjectEDISearch").Form.RecordSource 'Your record source if not a subform
  11. 'Set rs = CurrentDb.
  12.  
  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
  17.  
  18. ' You can add whatever other formatting you want by running Excel VBA throught the xlApp object
  19.  
  20. xlApp.Visible = True
  21.  
  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.

Thanks.

Jeff
Nov 16 '07 #1
2 19249
puppydogbuddy
1,923 Expert 1GB
Jeff,
it looks like you have already gotten your answer from allen browne.

http://groups.google.com/group/micro...6c06821e5648c6
Nov 18 '07 #2
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

3
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...
0
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...
0
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...
2
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...
1
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...
1
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...
1
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...
3
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.