473,396 Members | 2,098 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,396 software developers and data experts.

Export the filtered datasheet issue

Hi all,

I have a form named "Search"

In it their is a combobox "cboEmp", which is used to filter the data and display in datasheet.

Now, the filter is working fantastic. The problem persists when Export button comes into picture.

On clicking Export, the filtered data should be exported to the excel.

what exactly is happening is, the data are getting exported in excel , BUT not the current filtered data.

to get the current filtered data I have to close the form and reopen it and then only the data will be fetched, which should not happen.

I don't know where I am going wrong.

Please check and suggest. :)

'This is the code I am using under OnClick event of Export button
Expand|Select|Wrap|Line Numbers
  1.  DoCmd.OutputTo acOutputForm, "Tasks SubForm", acFormatXLS, "Tbl1XLS.xls", True
Jun 4 '15 #1
4 1981
zmbd
5,501 Expert Mod 4TB
please post the code used to set the form's filtering from the combobox too.

thnx
z
Jun 8 '15 #2
Hi z,

Thanks for atleast replying :)

The code on AfterUpdate event of the combobox is as shown:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboEmployee_AfterUpdate()
  2.  Dim Myemp As String
  3.     Myemp = "select * from Tasks where ([EmployeeId] =" & Me.cboEmployee & ")"
  4.     Me.Tasks_subform4.Form.RecordSource = Myemp
  5.     Me.Tasks_subform4.Requery  
  6. End Sub
Please note: I am getting all the data exported in Excel.

Also, the code in AfterUpdate() is working fine, as it is filtering the data as per the change.
Jun 9 '15 #3
zmbd
5,501 Expert Mod 4TB
"tasks_subform4"
vs
"Tasks Subform"

What is the difference between these? Do you have one form named "Tasks Subform" and another named "tasks_subform4"?

If this had been a simple filter, then I had a ready answer for you; however, in this case I'll have to do a little digging.
Jun 10 '15 #4
jforbes
1,107 Expert 1GB
I really don't know what will happen if you try to output a filtered Subform. It sounds problematic as DoCmd.OutputTo is quite finicky as it is, at least for me.

If you are still stuck on this, I would recommend a slightly different approach. I usually export to PDF. So I mocked this up from some code I use, to export to Excel and it seems to be working. This approach would require you to build a Report to export:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command0_Click()
  2.  
  3.     Dim sReportName As String
  4.     Dim sWhere As String
  5.  
  6.     sReportName = "OrderHistory"
  7.  
  8.     ' Define Where Clause
  9.     If Len(Me.txtStart.Value) > 0 Then sWhere = sWhere & " AND [CreatedDate]>=#" & Me.txtStart.Value & "#"
  10.     If Len(Me.txtEnd.Value) > 0 Then sWhere = sWhere & " AND [CreateDate]<=#" & Me.txtEnd.Value & "#"
  11.     If Len(sWhere) > 0 Then sWhere = Right(sWhere, Len(sWhere) - 5)
  12.  
  13.     ' Export Report
  14.     DoCmd.OpenReport sReportName, acViewPreview, , sWhere, acHidden
  15.     DoCmd.OutputTo acOutputReport, sReportName, acFormatXLS, "C:\Temp\TestExport.xls", True
  16.     DoCmd.Close acReport, sReportName
  17. End Sub
Jun 11 '15 #5

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

Similar topics

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...
2
by: Arvind R | last post by:
Hello, how to ask saveas dialog before writing the data to the excel file? right now im able to save in c drive or any other specified location only. any solution will be a great help! ...
4
by: dinoo | last post by:
I would appreciate if some one could help me out with this problem. I am trying to export the datagrid to an excel file in ASP.NET. The functionality works fine. But I would like to setup the...
1
by: simon.robin.jackson | last post by:
Ok. I have a database. I have a report. I want to batch export this report to either html/xml/rtf files. However, at present, the problem is that by default, I can batch export to html but it will...
2
by: Neo | last post by:
I am pasting sample code below which I call on a button click. My problem is that 6/7 is shown by excel as 7-Jun. I want it to look as 6/7 in excel. Please let me know if anyone has a solution. ...
5
by: karthick | last post by:
Hi, I am exporting a Gridview to Excel and it works fine without any issues. But as one of the field holds values such as "71646E100" it gets converted to: "7.16E+104" (like a formula) in...
1
by: icenemesis | last post by:
I have a form that searches dynamically based on what criteria the user enters. The resulting query populates a subform in datasheet view. If I wanted to have a button that would export the...
2
by: sstidham | last post by:
I'm a novice user of Access, maybe an intermediate on a good day and I've been building a database for my particular job. The database itself is complete, and I am now building the reports that I'll...
6
by: theberner | last post by:
I have a report, Report A, that pulls data from a Table, Table A. Table A, has a field, Field A, where I am to export Report A for each Unique Entery in Field A. Currently I have to do this...
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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
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...

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.