I have a report that opens up using a pretty complex query. I then pop up a form with combo boxes so the user can apply a filter to the existing report and then refresh the report. I need to export the report's records with the applied query to excel in datasheet form and it needs to contain the additional filters that the user selects. The reports datasource is the original query.
Right now I have this and get the datasheet format, but I need the filters that were passed to the report - how can I export the query with the additional filters?
'Export the query as a datasheet in excel - missing filters from user
DoCmd.OutputTo acOutputQuery, "BOM_QTY_Status _qry", acFormatXLS, strFileName, True
Thanks
6 6253 PEB 1,418
Recognized Expert Top Contributor
Hi,
Simply set up those filters directly in your query instaed of your reports
:)
pks00 280
Recognized Expert Contributor
Is it possible to export your report in excel?
I mean run your report in preview mode then analyze it with excel
e.g
DoCmd.OpenRepor t "MyReport", acViewPreview
DoCmd.RunComman d acCmdOutputToEx cel
NeoPa 32,573
Recognized Expert Moderator MVP
It is possible, but crap ;).
Not entirely, but the resultant spreadsheet has data in columns all over the place and is hard work to format into a useful document.
I am working on a similar job ATM and I decided to implement, in code, the application of the various filters into the underlying recordsource of the Report.
It doesn't use the data already run for the report.
I'll copy in the routine I'm using for ideas, but it uses functions you won't have available so it won't work for you directly. Even this one routine is quite large. I will however dig up the other stuff if requested - I don't wanna post a load of code here that no-one wants. I myself am always very cautious about using code developed elsewhere. - 'ExportToExcel exports recordset {strRS} to {strFolder}\{strName}.Xls
-
'Returns the eventual file name used
-
Public Function ExportToExcel(strName As String, _
-
Optional ByVal strRS As String = "", _
-
Optional ByVal strWhere As String = "", _
-
Optional ByVal strFolder As String = "") As String
-
Dim strOut As String, strFile As String, strType As String
-
Dim objRS As Object
-
-
'If no RecordSet supplied assume "tbl" & strName
-
If strRS = "" Then strRS = "tbl" & strName
-
'Determine the DataSet type (strType) - (T)able; (Q)uery; (S)QL
-
On Error Resume Next
-
Set objRS = CurrentDb.TableDefs(strRS)
-
If Not objRS Is Nothing Then
-
strType = "T"
-
Else
-
Set objRS = CurrentDb.QueryDefs(strRS)
-
strType = IIf(objRS Is Nothing, "S", "Q")
-
End If
-
On Error GoTo 0
-
'Code to insert a WHERE clause into the SQL from strWhere
-
If strWhere > "" Then
-
strRS = ParamReplace("SELECT * FROM (%S)%A WHERE (%W)", _
-
"%S", strRS, _
-
"%A", IIf(strType = "S", " AS subQ", ""), _
-
"%W", strWhere)
-
strType = "S"
-
End If
-
'If SQL string to be used - create temp query
-
If strType = "S" Then _
-
Set objRS = TempQuery(strName:=strName, strSQL:=strRS, blnCopy:=True)
-
'If no folder supplied, use the 'Temp' folder
-
If strFolder = "" Then strFolder = Environ("Temp")
-
'For uniformity, remove any trailing "\" from folder name
-
If Right(strFolder, 1) = "\" Then _
-
strFolder = Left(strFolder, Len(strFolder) - 1)
-
strOut = strFolder & "\" & strName & "New.Xls"
-
strFile = strFolder & "\" & strName & ".Xls"
-
'Delete temp file we will use, if it exists - if not, then not a problem
-
On Error Resume Next
-
Call Kill(strOut)
-
On Error GoTo 0
-
'Export to temp file - if this works then rename to required file
-
strName = objRS.Name
-
Set objRS = Nothing
-
Call DoCmd.TransferSpreadsheet(TransferType:=acExport, _
-
TableName:=strName, _
-
FileName:=strOut)
-
On Error Resume Next
-
Call Kill(strFile)
-
On Error GoTo 0
-
Name strOut As strFile
-
If strType = "S" Then Call CurrentDb.QueryDefs.Delete(Name:=strName)
-
ExportToExcel = strFile
-
End Function
To export a report to Excel is messy looking. Export a query instead, it exports in datasheet form. What I did was create a query that the report uses and a button on a form that says 'Export to Excel'. On the click event I call the query for the report being displayed and it has the command:
DoCmd.OutputTo acOutputQuery, "query_name_her e", acFormatXLS, "path_and_file_ name_here", True
NeoPa 32,573
Recognized Expert Moderator MVP
I'm doing a lot of work on exporting to Excel in my main database at work ATM.
I wasn't aware of that construct - I'll check into it tomorrow in case it's better than what I'm currently using (DoCmd.Transfer Spreadsheet).
My name is hunter bowker.
came here through google.
this forum seems to be ranking high on google.
btw what is the most busiest time on this forum so that i could interact with peak members or is it ever this lonely.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Steven Stewart |
last post by:
I have a user who has been using Excel for a while to keep statistics
and print reports. She finds using it cumbersome because of long
formulas and a lot of copying and pasting.
I have designed a database for her which is intended to make things a
lot easier; however, I don't have a lot of experience with Access and
I find that designing the reports in Access is tedious. I want to be
able to print the reports (which are simply based on...
|
by: PerryC |
last post by:
Is there a way to export an MS Access Report to Word/Excel that looks
EXACTLY like it appears in Access? When I export to Excel, only
certain data appears, titles, headings... all missing. The format is
not aligned... When export to Word, all my lines (table lines) are
gone, making it hard to read.
Thanks.
Perry
|
by: bonehead |
last post by:
Greetings,
I'm using the DoCmd.TransferText method to export the results of a MS
Access query to a csv file. The csv will then be used to load an Oracle
table.
In other systems such as TOAD for Oracle, it's possible to force an
additional comma delimiter after the last column, if the column is empty
on a particular row. Oracle requires this additional comma on empty
rightmost columns, for importing purposes.
|
by: Hemant Sipahimalani |
last post by:
The following piece of code is being used to export HTML to excel.
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename=ABC.xls")
HttpContext.Current.Response.Write(strHTML)
HttpContext.Current.Response.End()
However when the user tries to save it the Default File Type is Web
Page(*.htm; *.html)
|
by: JawzX01 |
last post by:
Hello All,
First, thank you for any help you can provide.
I'm trying to do a simple export to excel. I've used the classic
code that is all over the internet, and of course it worked without a
problem.
The problem is that I want to add text above the data grid in the
excel sheet. The text already exists on the web page in various panels
(there is different text depending on the parameters of the datagrid
| |
by: yovation |
last post by:
Hi,
I have a 3 table database.
1 parent
1 child
1 child of child
I would like to get the data into excel as 1 sheet (similar to a
grouped report).
|
by: hemantbasva |
last post by:
Note We need to have a template on server for generating report in multiple sheet
as we do not had msoffice on server
moreover this require a batch job to delete excel file created by the method....
it creates 6 sheets
# region Namespaces
using System;
|
by: barrhaven01 |
last post by:
Hi there,
I was wondering if anyone could suggest a method using only access ( ie no additional applications) to batch export reports to excel. Basically i have a report with a query for its source data, and the query is based on the selection of an employee from a drop down list. It would be terrific if i could batch export a report for each employee.
Hopefully someone out there has the answer
|
by: chandhseke |
last post by:
Hi folks,
I am a newbie to this functionality of creating excel report using VB/VB Script.
I have been given a code and asked to add filters to the excel sheet that is created using the below code.
Can somebody help me out in resloving the issue??
Thanks in advance.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |