472,961 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Please help: set recordsource of report

Hi all,

I've struggled with the following problem and welcome all a suggestions to
solve this.

I have a form that list records from a table with observations.
The record source for the table depends on from where the form is opened,
but always looks like:

SELECT tblObservation.* FROM tblObservation WHERE ...

Needless to say, it is the where clause that limits the records retrieved
from the backend (the db is split).
Once the form is open, filters can be applied.

What I would like to do, is open a report (rptObservationAndActions) from
the list form a described above.
But it should _only_ retrieve those observations that were preselected and
filtered in the listform.
The difficulty for me is that the report does not only contain data from
tblObservation, but also has a LEFT JOIN to tblAction.
So, the record source of the report is like:

SELECT tblObservation.*, tblAction.*
FROM tblObservation LEFT JOIN tblAction ON tblObservation.Observation_ID =
tblAction.Observation_ID;

For example there are 1000 records in tblObservation.
I do a select that gives me just a preselection of 100 records and after
that I apply some filter to the form that leaves me with a result of 5.
When I do the command 'print report' from the form, it should retrieve and
print only the same 5 records, including the details from tblAction.

How do I manage to set the correct recordsource to the report in this case?

Thanks in advance!

Kind regards, Koen
Nov 12 '05 #1
2 2871
It's simpler if the Form's RecordSource is SQL (but if it is a saved query,
you can get the SQL from the query's SQL property). You'll have to combine
the criteria in the WHERE with the criteria in the Form's Filter property
and construct the SQL you want for the Report. As long as the Form is open
when you open the Report, you can pick up the information in the Report's
Open event from the Form.

Larry Linson
Microsoft Access MVP

"Koen" <no@spam.nl> wrote in message
news:Xn*********************@194.109.133.20...
Hi all,

I've struggled with the following problem and welcome all a suggestions to
solve this.

I have a form that list records from a table with observations.
The record source for the table depends on from where the form is opened,
but always looks like:

SELECT tblObservation.* FROM tblObservation WHERE ...

Needless to say, it is the where clause that limits the records retrieved
from the backend (the db is split).
Once the form is open, filters can be applied.

What I would like to do, is open a report (rptObservationAndActions) from
the list form a described above.
But it should _only_ retrieve those observations that were preselected and
filtered in the listform.
The difficulty for me is that the report does not only contain data from
tblObservation, but also has a LEFT JOIN to tblAction.
So, the record source of the report is like:

SELECT tblObservation.*, tblAction.*
FROM tblObservation LEFT JOIN tblAction ON tblObservation.Observation_ID =
tblAction.Observation_ID;

For example there are 1000 records in tblObservation.
I do a select that gives me just a preselection of 100 records and after
that I apply some filter to the form that leaves me with a result of 5.
When I do the command 'print report' from the form, it should retrieve and
print only the same 5 records, including the details from tblAction.

How do I manage to set the correct recordsource to the report in this case?
Thanks in advance!

Kind regards, Koen

Nov 12 '05 #2
Koen wrote:
Hi all,

I've struggled with the following problem and welcome all a suggestions to
solve this.

I have a form that list records from a table with observations.
The record source for the table depends on from where the form is opened,
but always looks like:

SELECT tblObservation.* FROM tblObservation WHERE ...

Needless to say, it is the where clause that limits the records retrieved
from the backend (the db is split).
Once the form is open, filters can be applied.

What I would like to do, is open a report (rptObservationAndActions) from
the list form a described above.
But it should _only_ retrieve those observations that were preselected and
filtered in the listform.
The difficulty for me is that the report does not only contain data from
tblObservation, but also has a LEFT JOIN to tblAction.
So, the record source of the report is like:

SELECT tblObservation.*, tblAction.*
FROM tblObservation LEFT JOIN tblAction ON tblObservation.Observation_ID =
tblAction.Observation_ID;

For example there are 1000 records in tblObservation.
I do a select that gives me just a preselection of 100 records and after
that I apply some filter to the form that leaves me with a result of 5.
When I do the command 'print report' from the form, it should retrieve and
print only the same 5 records, including the details from tblAction.

How do I manage to set the correct recordsource to the report in this case?

Thanks in advance!

Kind regards, Koen


Have you considered passing a filter?

Docmd.OpenReport "ReportName",,,"whereclause"

Your "whereclause" should be a valid whereclause WITHOUT the word "Where" ExL

Docmd.OpenReport "ReportName",,,"WHERE customerid = 1" XXX BAD NO GOOD

Docmd.OpenReport "ReportName",,,"customerid = 1" 'Good OK

Remember...in filters strings in quotes, dates between #, and numbers has
nothing around it. Ex:
Var = 1
Docmd.OpenReport "ReportName",,,"customerid = " & var

Var = Date()
Docmd.OpenReport "ReportName",,,"Datefld = #" & var & "#"

Var = "Hello"
Docmd.OpenReport "ReportName",,,"customertext = ' " & var & " ' "
remove the spaces between quotes in above example.

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jayjay | last post by:
When it comes to access, I'm pretty good using the built in features and can come up with some pretty complex functions to get what I need. But we have this database I'm doing for work that is...
9
by: mooseshoes | last post by:
All: I'm using Access 2000 on a Windows XP platform. My goal is to use a form to gather user criteria which I will then parse into a useable SQL string. At this point I would like to open one...
15
by: Richard Hollenbeck | last post by:
I tried to ask this question before on the 14th of January but I never got a reply. I'm still struggling with the problem. I'll try to rephrase the question: I have a crosstab query with rows...
1
by: George Kandaz | last post by:
Steve, I posted a question to your last post almost a week ago, but never heard from you again. Please read my last message, as follows. Thanks. ...
3
by: Patrik | last post by:
I am changing the recorsource in the onopen event of my report simply using this line : RecordSource = "SELECT * FROM tbl_Temp_ImpressionQuestionnaire WHERE Num_Questionnaire = 19" However...
7
by: themastertaylor | last post by:
Hi, I work for a construction company and part of my job is sourcing materials. currently we have a spreadsheet based system whereby each site has a worksheet in the workbook with the standard...
3
by: Birky | last post by:
Hello, I’m hoping you can help me out with two issues I’m having with my code. I have an Access Report named Report_Project_Event_Log which I have calling a Form named “Custom_Code_lookup” which...
3
by: Don | last post by:
I have a "Report" that is created from a "Form". It prints a list of items, you may consider it a shopping list. In any event I use to run this in alphabetical order but have since decided to run...
3
by: Simon van Beek | last post by:
Dear reader, How to change the RecordSource for a subReport. For forms the syntaxes is:
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.