473,386 Members | 1,962 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.

Using one report for different queries

I have a report to print envelopes. The report is based on a query. Now I
need to make 10 more queries to make different selections of addresses.
Every query has the same output fields as the already existing query. I know
I can copy the report and base it on another query but then I would have to
make 10 extra reports. How can I use just one report for all of the queries?
At the moment I use the button wizard in my forms to make buttons that start
the particular reports. Resulting code looks like this:

Private Sub Knop34_Click()
On Error GoTo Err_Knop29_Click

Dim stDocName As String

stDocName = "Alle leden per Bezorgcategorie"
DoCmd.OpenReport stDocName, acPreview

Exit_Knop29_Click:
Exit Sub

Can I perhaps add some code that points which query the report should be
based on?
Thanks,
john
Aug 31 '06 #1
10 2546
What is different about your 10 queries? It seems to me like you
should be able to do all of this with one query, one report, and
perhaps a filter.

john wrote:
I have a report to print envelopes. The report is based on a query. Now I
need to make 10 more queries to make different selections of addresses.
Every query has the same output fields as the already existing query. I know
I can copy the report and base it on another query but then I would have to
make 10 extra reports. How can I use just one report for all of the queries?
At the moment I use the button wizard in my forms to make buttons that start
the particular reports. Resulting code looks like this:

Private Sub Knop34_Click()
On Error GoTo Err_Knop29_Click

Dim stDocName As String

stDocName = "Alle leden per Bezorgcategorie"
DoCmd.OpenReport stDocName, acPreview

Exit_Knop29_Click:
Exit Sub

Can I perhaps add some code that points which query the report should be
based on?
Thanks,
john
Aug 31 '06 #2

Jeff L wrote:
What is different about your 10 queries? It seems to me like you
should be able to do all of this with one query, one report, and
perhaps a filter.
If you look at the OpenReport method, you will see that one of the
arguments is "Where Condition", which is any valid Where clause (minus
the WHERE keyword).
DoCmd.OpenReport "MyReport", acViewPreview, , "[FieldX]= '" &
Forms![MyOpenForm]![txtValue] & "'"

Aug 31 '06 #3
The differences between the queries are the selection criteria. For
instance:
1. All members
2. This year's new members
3. Members of a specific zipcode area
4. Female members
5. This year's male members
etc.
I don't know how to put this in one query or report.
john

"Jeff L" <jl*******@hotmail.comschreef in bericht
news:11**********************@m73g2000cwd.googlegr oups.com...
What is different about your 10 queries? It seems to me like you
should be able to do all of this with one query, one report, and
perhaps a filter.

john wrote:
>I have a report to print envelopes. The report is based on a query. Now I
need to make 10 more queries to make different selections of addresses.
Every query has the same output fields as the already existing query. I
know
I can copy the report and base it on another query but then I would have
to
make 10 extra reports. How can I use just one report for all of the
queries?
At the moment I use the button wizard in my forms to make buttons that
start
the particular reports. Resulting code looks like this:

Private Sub Knop34_Click()
On Error GoTo Err_Knop29_Click

Dim stDocName As String

stDocName = "Alle leden per Bezorgcategorie"
DoCmd.OpenReport stDocName, acPreview

Exit_Knop29_Click:
Exit Sub

Can I perhaps add some code that points which query the report should be
based on?
Thanks,
john

Aug 31 '06 #4
john wrote:
The differences between the queries are the selection criteria. For
instance:
1. All members
2. This year's new members
3. Members of a specific zipcode area
4. Female members
5. This year's male members
etc.
I don't know how to put this in one query or report.
john
Let's say you have a query like this
Select Emp.* From Employee
This will select all employees

Select Emp.* From Employee Where Sex = "M"
This will select all employees flagges as males

Prior to opening the report you should create/store the "Where clause"
of the SQL (the part that filters the returned records) to a
variable...without the word "Where"...and pass that when opeing the
report. Ex:
"Sex = ""M""
is valid since it does not include the predicate Where.

Now, if you really needed to change the recordsource, you could do that
too. Let's say you had an Employee table and a customer table and the
report could come from any of those sources. I think in the newer
versions of Access you can pass an argument to a report, in Acess97 you
can't...so I'll use the A97 method. Let's say you had 2 queries; EmpQry
and CustQry. The report defaults to using CustQry. In the form
(RptForm) that calls the report, create a hidden field (WhichSource)
that stores either a "C" or "E" in it. THen in the OnOpen event you can
have code similar to this.

If Forms!RptForm!WhichSource = "E" Then
Me.Recordsource = "EmpQry"
Endif
Since the default is for customers, this will change the recordsource to
the Employee query. The fields in the report should be the name in both
queries.

Let's say a field in Customers is CustomerID. How do you use the same
field from the Employee table? Simple, drag the EmployeeID field to a
column. Then in front of it, add the word CustomerID with a colon. Ex:
CustomerID : EmployeeID
Now when you reference the column, it will be referenced using
CustomerID. IOW, you created an alias for the field.

"Jeff L" <jl*******@hotmail.comschreef in bericht
news:11**********************@m73g2000cwd.googlegr oups.com...
>>What is different about your 10 queries? It seems to me like you
should be able to do all of this with one query, one report, and
perhaps a filter.

john wrote:
>>>I have a report to print envelopes. The report is based on a query. Now I
need to make 10 more queries to make different selections of addresses.
Every query has the same output fields as the already existing query. I
know
I can copy the report and base it on another query but then I would have
to
make 10 extra reports. How can I use just one report for all of the
queries?
At the moment I use the button wizard in my forms to make buttons that
start
the particular reports. Resulting code looks like this:

Private Sub Knop34_Click()
On Error GoTo Err_Knop29_Click

Dim stDocName As String

stDocName = "Alle leden per Bezorgcategorie"
DoCmd.OpenReport stDocName, acPreview

Exit_Knop29_Click:
Exit Sub

Can I perhaps add some code that points which query the report should be
based on?
Thanks,
john

Aug 31 '06 #5
On Thu, 31 Aug 2006 21:19:59 +0200, john wrote:
The differences between the queries are the selection criteria. For
instance:
1. All members
2. This year's new members
3. Members of a specific zipcode area
4. Female members
5. This year's male members
etc.
I don't know how to put this in one query or report.
john

"Jeff L" <jl*******@hotmail.comschreef in bericht
news:11**********************@m73g2000cwd.googlegr oups.com...
>What is different about your 10 queries? It seems to me like you
should be able to do all of this with one query, one report, and
perhaps a filter.

john wrote:
>>I have a report to print envelopes. The report is based on a query. Now I
need to make 10 more queries to make different selections of addresses.
Every query has the same output fields as the already existing query. I
know
I can copy the report and base it on another query but then I would have
to
make 10 extra reports. How can I use just one report for all of the
queries?
At the moment I use the button wizard in my forms to make buttons that
start
the particular reports. Resulting code looks like this:

Private Sub Knop34_Click()
On Error GoTo Err_Knop29_Click

Dim stDocName As String

stDocName = "Alle leden per Bezorgcategorie"
DoCmd.OpenReport stDocName, acPreview

Exit_Knop29_Click:
Exit Sub

Can I perhaps add some code that points which query the report should be
based on?
Thanks,
john

How are you currently selecting which report to run?
To use just one report (which is the correct method) and yet return
different sets of data ....
Let's say you have a form with an option group to select which report
data you want.

1 All Members
2 New Members
3 ZipCode
4 Female
5 Male

You would also have an unbound text control on the form (to enter the
wanted ZipCode in).

Add a command button to the form.
Code it's Click event something like:
Dim strWhere as string
Select Case OptionGroupName
Case is = 2
strWhere = "NewMember = -1"
Case is = 3
strWhere = "[ZipCode] = '" & Me![ControlOnFormName] & "'"
Case is = 4
strWhere = "Gender = 'Female'"
Case is = 5
strWhere = "Gender = 'Male'"
End Select
DoCmd.OpenReport "ReportName", acViewPreview, , strWhere

The above is just a generalized method. I have no idea how you
determine, in your database, who is a new or old member, or how you
store the data of who is male or female. If Option 1 is selected, all
the records will be returned.
You can adapt the above to your actual database.

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Aug 31 '06 #6
Ok. It sounds like your first one, All Members is the most
comprehensive list. So basically, the other queries you made are All
Members query but with some criteria done to it to get a smaller list.
Correct?

You should be able to take the All Members query and make that the data
source of your report. Now when the report is opened, you pass it some
criteria depending on which list you want as the other person's post
suggested.
john wrote:
The differences between the queries are the selection criteria. For
instance:
1. All members
2. This year's new members
3. Members of a specific zipcode area
4. Female members
5. This year's male members
etc.
I don't know how to put this in one query or report.
john

"Jeff L" <jl*******@hotmail.comschreef in bericht
news:11**********************@m73g2000cwd.googlegr oups.com...
What is different about your 10 queries? It seems to me like you
should be able to do all of this with one query, one report, and
perhaps a filter.

john wrote:
I have a report to print envelopes. The report is based on a query. Now I
need to make 10 more queries to make different selections of addresses.
Every query has the same output fields as the already existing query. I
know
I can copy the report and base it on another query but then I would have
to
make 10 extra reports. How can I use just one report for all of the
queries?
At the moment I use the button wizard in my forms to make buttons that
start
the particular reports. Resulting code looks like this:

Private Sub Knop34_Click()
On Error GoTo Err_Knop29_Click

Dim stDocName As String

stDocName = "Alle leden per Bezorgcategorie"
DoCmd.OpenReport stDocName, acPreview

Exit_Knop29_Click:
Exit Sub

Can I perhaps add some code that points which query the report should be
based on?
Thanks,
john
Aug 31 '06 #7
Thanks.

I fiddled with the filter and all kinds of different quotations and copies
from the sql query but I can't get it to work. This is one the things I
tried and partly works:

Dim stDocName As String
Dim stWhere As String

stDocName = "All male members"
stWhere = "[MF] = M"
DoCmd.OpenReport stDocName, acPreview, , sWhere

It gives me a dialog where it shows the M. If I enter an M there the filter
works.
john

"salad" <oi*@vinegar.comschreef in bericht
news:WV****************@newsread4.news.pas.earthli nk.net...
john wrote:
>The differences between the queries are the selection criteria. For
instance:
1. All members
2. This year's new members
3. Members of a specific zipcode area
4. Female members
5. This year's male members
etc.
I don't know how to put this in one query or report.
john

Let's say you have a query like this
Select Emp.* From Employee
This will select all employees

Select Emp.* From Employee Where Sex = "M"
This will select all employees flagges as males

Prior to opening the report you should create/store the "Where clause" of
the SQL (the part that filters the returned records) to a
variable...without the word "Where"...and pass that when opeing the
report. Ex:
"Sex = ""M""
is valid since it does not include the predicate Where.

Now, if you really needed to change the recordsource, you could do that
too. Let's say you had an Employee table and a customer table and the
report could come from any of those sources. I think in the newer
versions of Access you can pass an argument to a report, in Acess97 you
can't...so I'll use the A97 method. Let's say you had 2 queries; EmpQry
and CustQry. The report defaults to using CustQry. In the form (RptForm)
that calls the report, create a hidden field (WhichSource) that stores
either a "C" or "E" in it. THen in the OnOpen event you can have code
similar to this.

If Forms!RptForm!WhichSource = "E" Then
Me.Recordsource = "EmpQry"
Endif
Since the default is for customers, this will change the recordsource to
the Employee query. The fields in the report should be the name in both
queries.

Let's say a field in Customers is CustomerID. How do you use the same
field from the Employee table? Simple, drag the EmployeeID field to a
column. Then in front of it, add the word CustomerID with a colon. Ex:
CustomerID : EmployeeID
Now when you reference the column, it will be referenced using CustomerID.
IOW, you created an alias for the field.

>"Jeff L" <jl*******@hotmail.comschreef in bericht
news:11**********************@m73g2000cwd.googleg roups.com...
>>>What is different about your 10 queries? It seems to me like you
should be able to do all of this with one query, one report, and
perhaps a filter.

john wrote:

I have a report to print envelopes. The report is based on a query. Now
I
need to make 10 more queries to make different selections of addresses.
Every query has the same output fields as the already existing query. I
know
I can copy the report and base it on another query but then I would have
to
make 10 extra reports. How can I use just one report for all of the
queries?
At the moment I use the button wizard in my forms to make buttons that
start
the particular reports. Resulting code looks like this:

Private Sub Knop34_Click()
On Error GoTo Err_Knop29_Click

Dim stDocName As String

stDocName = "Alle leden per Bezorgcategorie"
DoCmd.OpenReport stDocName, acPreview

Exit_Knop29_Click:
Exit Sub

Can I perhaps add some code that points which query the report should be
based on?
Thanks,
john
Aug 31 '06 #8
Got it working now with:
stWhere = "MF = 'M'"
john

"john" <jo**@test.comschreef in bericht
news:Vu********************@casema.nl...
Thanks.

I fiddled with the filter and all kinds of different quotations and copies
from the sql query but I can't get it to work. This is one the things I
tried and partly works:

Dim stDocName As String
Dim stWhere As String

stDocName = "All male members"
stWhere = "[MF] = M"
DoCmd.OpenReport stDocName, acPreview, , sWhere

It gives me a dialog where it shows the M. If I enter an M there the
filter works.
john

"salad" <oi*@vinegar.comschreef in bericht
news:WV****************@newsread4.news.pas.earthli nk.net...
>john wrote:
>>The differences between the queries are the selection criteria. For
instance:
1. All members
2. This year's new members
3. Members of a specific zipcode area
4. Female members
5. This year's male members
etc.
I don't know how to put this in one query or report.
john

Let's say you have a query like this
Select Emp.* From Employee
This will select all employees

Select Emp.* From Employee Where Sex = "M"
This will select all employees flagges as males

Prior to opening the report you should create/store the "Where clause" of
the SQL (the part that filters the returned records) to a
variable...without the word "Where"...and pass that when opeing the
report. Ex:
"Sex = ""M""
is valid since it does not include the predicate Where.

Now, if you really needed to change the recordsource, you could do that
too. Let's say you had an Employee table and a customer table and the
report could come from any of those sources. I think in the newer
versions of Access you can pass an argument to a report, in Acess97 you
can't...so I'll use the A97 method. Let's say you had 2 queries; EmpQry
and CustQry. The report defaults to using CustQry. In the form
(RptForm) that calls the report, create a hidden field (WhichSource) that
stores either a "C" or "E" in it. THen in the OnOpen event you can have
code similar to this.

If Forms!RptForm!WhichSource = "E" Then
Me.Recordsource = "EmpQry"
Endif
Since the default is for customers, this will change the recordsource to
the Employee query. The fields in the report should be the name in both
queries.

Let's say a field in Customers is CustomerID. How do you use the same
field from the Employee table? Simple, drag the EmployeeID field to a
column. Then in front of it, add the word CustomerID with a colon. Ex:
CustomerID : EmployeeID
Now when you reference the column, it will be referenced using
CustomerID. IOW, you created an alias for the field.

>>"Jeff L" <jl*******@hotmail.comschreef in bericht
news:11**********************@m73g2000cwd.google groups.com...

What is different about your 10 queries? It seems to me like you
should be able to do all of this with one query, one report, and
perhaps a filter.

john wrote:

>I have a report to print envelopes. The report is based on a query. Now
>I
>need to make 10 more queries to make different selections of addresses.
>Every query has the same output fields as the already existing query. I
>know
>I can copy the report and base it on another query but then I would
>have to
>make 10 extra reports. How can I use just one report for all of the
>queries?
>At the moment I use the button wizard in my forms to make buttons that
>start
>the particular reports. Resulting code looks like this:
>
>Private Sub Knop34_Click()
>On Error GoTo Err_Knop29_Click
>
Dim stDocName As String
>
stDocName = "Alle leden per Bezorgcategorie"
DoCmd.OpenReport stDocName, acPreview
>
>Exit_Knop29_Click:
Exit Sub
>
>Can I perhaps add some code that points which query the report should
>be
>based on?
>Thanks,
>john


Aug 31 '06 #9
"fredg" <fg******@example.invalidschreef in bericht
How are you currently selecting which report to run?
By pushing a button (one button for every report).
Add a command button to the form.
Code it's Click event something like:
Dim strWhere as string
Select Case OptionGroupName
Case is = 2
strWhere = "NewMember = -1"
Case is = 3
strWhere = "[ZipCode] = '" & Me![ControlOnFormName] & "'"
Case is = 4
strWhere = "Gender = 'Female'"
Case is = 5
strWhere = "Gender = 'Male'"
End Select
DoCmd.OpenReport "ReportName", acViewPreview, , strWhere

The above is just a generalized method. I have no idea how you
determine, in your database, who is a new or old member, or how you
store the data of who is male or female. If Option 1 is selected, all
the records will be returned.
You can adapt the above to your actual database.
Good idea! Thanks.
john

Aug 31 '06 #10
"Jeff L" <jl*******@hotmail.comschreef in bericht
news:11**********************@m79g2000cwm.googlegr oups.com...
Ok. It sounds like your first one, All Members is the most
comprehensive list. So basically, the other queries you made are All
Members query but with some criteria done to it to get a smaller list.
Correct?
Yes.
You should be able to take the All Members query and make that the data
source of your report. Now when the report is opened, you pass it some
criteria depending on which list you want as the other person's post
suggested.
Thanks...
.... to all for your great help! :-)
john
Aug 31 '06 #11

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

Similar topics

1
by: Steve | last post by:
I am using Access 2000 and I have a DB that is currently running four different queries from some Forms and subforms. These queries each have a date field that are seperate from each other that are...
1
by: Simon Matthews | last post by:
Hope someone can help an Access beginner! I've just started keeping my surgical logbook on access and it's a simple flat-file affair. I have created several queries that will list cases...
1
by: Fred Zuckerman | last post by:
I have 8 reports that I want to run. Each report is only about 6-7 lines long. I'd like to get them all on a single page. So I created a parent report and made each of the 8 desired reports a...
1
by: Chasing Gates | last post by:
I have created a database that brings in a new table weekly. I then made a separate query for each sales rep and a separate report for each rep. (The reports are all identical but call different...
10
by: Robert | last post by:
How do you get an accurate count of the number of records returned from a query when using linked tables. I have an access 2003 database as a front end to another access 2003 database that...
4
by: Jimmy | last post by:
I have a form with a command button on it that is supposed to open up a report and use a query to populate it. DoCmd.OpenReport "rptMailingList", acViewPreview, "qryMailingListChristmas" ...
3
by: iht | last post by:
Say I have a database with types of car driven by people living in different cities. I made several queries to separate out the database according to city, then made queries to count out numbers...
3
by: nsymiakakis | last post by:
Hi everyone, I am hoping you can help me on this problem. I created 3 queries, each gives me a grand total Sum from various fields in 2 different tables. This part works great. Now I am trying to...
5
by: Gumbyu | last post by:
Hello all, I have been working on this issue for about a week and still cannot get anything to group or sort. At this point, I just want to be able to group a report by using a 'checkbox' on a form....
0
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,...
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
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: 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:
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
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.