I would like to redirect a form to output it's recordset to Excel
rather than the Access report. I have the code to send SQL or a
recordset to Excel, but how do I extract the datasource from the
report? This would be at runtime, either when the form is called from
another form or on the on_open event of the report. 5 3705
You can try this to have the datasource for your report pushed to a
recordset:
Private Sub Report_Open(Cancel As Integer)
Dim dbs As Database
Dim rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(Me.RecordSource)
'Put your code to send the recordset to Excel here
End Sub
I'm running into a problem. These reports are being opened with a
filter via docmd:
DoCmd.OpenReport stDocName, acPreview, , strCriteria
When I do the above I lose the strCriteria filter.
I do a similar thing, and it works ok for me....
objAccess.DoCmd.OpenReport sReport, acView, , sWhere
when you say 'lose', do you mean its there in the variable, but the
report seems to ignore it?
or do you mean that strCriteria var is empty?
some things to check.
* did you cut and paste this line of code into this posting? or did
you rekey it? I ask because the two commas after acPreview are
critical to hold the position of the strCriteria argument.
* you don't show the code leading up to this statement, i assume you've
trapped through and actually see the where codition in the strCriteria
var?
* assuming you have the where text in the var, are u sure it works? if
you have some complicated stuff in there, you may just have an error in
it. run the where from access directly to test it.
* if you can't find anything wrong with the strCriteria expression,
then change it anyway to something really simple like "name = 'smith'",
"cost > 100" and see if the report filters on that simple thing.
My problem is when if call the me.recordsource, I get the base
recordset of the report without the criteria in in strcriteria applied.
for example, me.recordsource will give me the string "qry_ReportQuery".
But when I opened the form I had also passed a where condition in
strCriteria of "[Item] = '1224'".
My short term fix has benn to generate a sql string
strMyVar = "Select * from " & me.reports.recordsource & " where " &
me.reports.filter.
This SQL then gets passed to a function export to Excel. But it just
feels to cumbersome and prone to create problems down the line.
Here is another way, whether it's better or not, I can't say:
Dim dbs As Database
Dim rstTemp, rstFinal As Recordset
Set dbs = CurrentDb()
Set rstTemp = dbs.OpenRecordset(Me.RecordSource)
rstTemp.Filter = Me.Filter
Set rstFinal = rstTemp.OpenRecordset
Then use the rstFinal recordset in the code that pushes to Excel.
HTH,
Jana This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Michael Malinsky |
last post by:
I'm attempting to create a database which will take information from
one (perhaps two) tables and utilize that information to return
queries to a report designed in Excel.
The general idea I...
|
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...
|
by: somanyusernamesaretakenal |
last post by:
What I am trying to achieve:
Basically I have generated a report in access. This report needs to be updated using excel. (Updating the new data, not changing existing data)
What I did was I...
|
by: Sajit |
last post by:
I am trying to use an Excel file as a
template for an Access report. I Linked
the Excel file through an unbound frame as
an OLE object with the properties set as
follows:
Source Doc...
|
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...
|
by: pixie |
last post by:
Hi. Access 2003. The database stores contract information. I have a query for each person that is responsible for contracts. The query checks to see if there are reports due either this week,...
|
by: Sport Girl |
last post by:
Hi everybody ,
i have the task of developing in Perl a script that retrieves data from 3 tables ( bugs, profiles, products) from a MySQL database called bugs and display them in an excel sheet...
|
by: billa856 |
last post by:
Hi,
I have project in Access.
Now I am generating report in it.
When I select an Item from combobox and click on Search button then Report Apperar to me After that I want to Send it to Excel by...
|
by: Eddie |
last post by:
Hi all,
I am displaying a number of reports, and giving the users an option to
display them on the web or download them to Excel. If they want the
Excel file, I just use the PHP header command...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
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$) {
}
...
|
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...
| |