473,387 Members | 1,590 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,387 software developers and data experts.

How can I pass a query parameter to a report with >1 use of the same query?

Hi there,

I am designing an Access report that will employ the same query ("Attendance") multiple times.

Attendance accepts one parameter: Month ("...WHERE classmonth = [Month]"), and I have 12 sub-forms in my main form, each employing an instance of Attendance but with a different month supplied. Currently when I run the Attendance query a dialog box asks me to specify the month.

I actually have to run the query 12 distinct times; I cannot have the month supplied in the query itself, and thus cannot apply a simple filter to the query on month. I simplified the actual situation to get to the crux of my problem and prevent an overly long post.

I want to be able to use the same query 12 times in this report rather than having to save the query 12 distinct times.

Any ideas?

Thanks!
Mar 5 '14 #1
14 1283
Rabbit
12,516 Expert Mod 8TB
Just leave out the filter altogether and return month in the query. No need to run it 12 times. Run it once and return all the data.
Mar 5 '14 #2
NeoPa
32,556 Expert Mod 16PB
It can be helpful to simplify a question. On the other hand, simplifying often leaves out the crux of the matter.

As Rabbit says, the most sensible approach appears to be to include the month in the data. Each subform then filters for its own required month.

If that's not possible for any reason then that's definitely important information to include in the question.
Mar 5 '14 #3
Hah, fair enough!

So, here's a better explanation; keep in mind that month is no longer the problem.

I'm tracking attendance data across 2 months in the various programs at my school. A student may be involved in more than 1 program.

One of the stats I'm trying to generate is retention (a student was enrolled in the Spanish program in January and also in February). That one's a simple join on the student_id and program_name across the 2 months.

Growth is where I'm having a problem. This is the situation where the student was not enrolled in Spanish in January but is enrolled in February. I can't join on program_name because no record exists for January.

However if I specify program_name as a parameter then I can do an outer join (where progam_name IS NULL in January).

So that's why I have to manually specify the program name and why I can't filter by it.

Thanks.
Mar 6 '14 #4
NeoPa
32,556 Expert Mod 16PB
If your looking for the growth of Spanish (for instance) and you've linked with a LEFT JOIN then you still have to filter by 'Spanish'. You just need also to filter by Null. The first filtered field will be from the primary record source and the second (Null) will be from the secondary one. You still filter the values returned in your data - whichever way you look at it.
Mar 6 '14 #5
Right. I am filtering by program = "Spanish", and that filter is user-defined. I hadn't thought of it that way but you're absolutely correct.

So how can I have my report pass 'Spanish' to 1 instance of the query and 'French' to another instance, both in the same report?

Thanks.
Mar 7 '14 #6
NeoPa
32,556 Expert Mod 16PB
That's hard to answer as only you have a good understanding of how these separate references to the query are addressed in your database. However they are referenced though, you use that as a qualifier for the reference to the particular field.

Say the field is called [Program] and the query is called [qryProgInfo], but referenced in the first instance as [qryPI01] and the other as [qryPI02]. Then your filtering would be something like :
Expand|Select|Wrap|Line Numbers
  1. ([qryPI01].[Program]='Spanish') AND ([qryPI02].[Program]='French')
Mar 7 '14 #7
Hmmm I'm not sure I'm getting my question across clearly.

First, the query I'm using. It relies on two other queries which don't have parameters so I think can safely be omitted as they'd make the code more complicated and harder to read. lastMonth() is a variable that I define using VBA. I do this instead of using a parameter because lastMonth changes every month and several other queries rely on this variable (ie. I can change several queries in one place).
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT lastMonth() AS [Grew In], oma.customerid, oma.[last name], oma.[first name], oma.program
  2. FROM [Attendance: two months past] AS tma RIGHT JOIN [Attendance: one month past] AS oma ON (oma.program=tma.program) AND (oma.customerid=tma.customerid)
  3. WHERE oma.program=[Prog] And tma.program Is Null
  4. ORDER BY oma.customerid;
  5.  
In my report I want this query to report twice ("Q1" "Q2"): once where [Prog] = 'Spanish' and once where [Prog] = 'French'. And for conceivably more programs as my school grows. I'm doing this by drag-and-dropping the query twice into my report. So I'm trying to make a report with two sub-reports.

How to I get the report to automatically supply [Prog] = "Spanish" to the Q1 report and [Prog] = "French" to the Q2 report?

Thanks!
Mar 13 '14 #8
NeoPa
32,556 Expert Mod 16PB
I cannot add any more than I have already as there is no new and relevant information in your post.
Mar 13 '14 #9
Hey NeoPa,

I'm afraid I don't understand where I would apply your suggestion:

Expand|Select|Wrap|Line Numbers
  1. ([qryPI01].[Program]='Spanish') AND ([qryPI02].[Program]='French')
Does this go somewhere in the Report or in the query?

I appreciate the help you've supplied so far but I'm having trouble figuring out what you're suggesting.
Mar 14 '14 #10
NeoPa
32,556 Expert Mod 16PB
... and for my part I'm finding your explanations leave me without much idea of what you want help with. I have [qryPI01] & [qryPI02] and you have something else. Until you can make it clear what you have then I cannot make the answer any clearer for you. One thing depends directly on the other.

What are your subreports called? What do they use as a record source?

If you can tell me the names of the sub-report objects that contain the reports you're referring to I can help you set the .Filter property in order to filter one by 'Spanish' and the other by 'French'. Without that information from you though, I am in no position to tell you any more than I have already. I'm scrabbling in the dark.
Mar 14 '14 #11
Thanks; I'll do my best to give useful information.

OK, my main report is called 'Monthly report' and has 3 sub-reports
  • French growth
  • Spanish growth
  • German growth

Each of the sub-reports use the same query, 'Program growth' , as their record source:
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT lastMonth() AS [Grew In], oma.customerid, oma.[last name], oma.[first name], oma.program
  2. FROM [Attendance: two months past] AS tma
  3. RIGHT JOIN [Attendance: one month past] AS oma
  4. ON oma.program = tma.program
  5. AND oma.customerid = tma.customerid
  6. WHERE oma.program = [Prog]
  7. AND tma.program IS NULL
  8. ORDER BY oma.customerid
When I run the report I'm prompted three times for [Prog], whose inputs are 'French', 'Spanish', and 'German', respectively.

I'm trying to have the 'French growth' sub-report automatically supply the parameter 'French' to it's record source's [Prog] parameter, ('Spanish growth' automatically supplied 'Spanish', etc). when 'Monthly report' is run.

Thanks!
Mar 16 '14 #12
NeoPa
32,556 Expert Mod 16PB
Excellent. Change the SQL to the following :
Expand|Select|Wrap|Line Numbers
  1. ...
  2. WHERE oma.Program Is Not Null
  3.   AND tma.Program Is Null
  4. ...
Now, for each subreport object, set the .Filter property to :
Expand|Select|Wrap|Line Numbers
  1. ([Program]='French')
Change this for the other subreports to reflect the required language.
Mar 17 '14 #13
This helped brilliantly NeoPa.. sort of.

Your SQL suggestion eliminated the need for me to make 'program' a parameter in the first place (my earlier attempts with SQL gave me false-positive cross-products and I concluded executing the query once-per-program was just my lot in life), so thanks!

But, for the sake of completeness, I couldn't the .Filter property in my sub-report. Clicking around in different parts of the report reveals different properties but never the .Filter. I have seen .Filter before but I couldn't find it this time around.

At any rate I didn't search too carefully for it because you solved my problem in a different way.

Thanks so much for your patience and advice!
Mar 19 '14 #14
NeoPa
32,556 Expert Mod 16PB
Good point. The .Filter property is of the Report object and not of the Subreport object of a Report.

As it's perfectly possible that you're using the same actual Report object to go into each of your Subreports it may not make sense to set the .Filter for the Report (used in the Subreports) as part of the inherent design. However, you can set it at run-time.

The main Report's .OnOpen or .OnLoad event procedure can be set up to handle the updating of the .Filter property of the Reports in each of the Subreports.
Mar 19 '14 #15

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

Similar topics

3
by: Mark Horton | last post by:
I thought would be a super simple project, but I was wrong. I need Help!!!! I am using the Word.Application.Mailmerge.OpenDataSource to try and send a Dynamic Query to my stated Document.Open...
4
by: dixie | last post by:
I have an extended multi-select list box of names in which the bound column is a person ID field called ID (text, not numerical). I want that list to act as a parameter in a query that is...
1
by: ED | last post by:
I currently have an ODBC query that hits an Oracle database. I want to bring back records for a given month based on a job completion date in the Oracle database. I would like to have the user...
2
by: amith.srinivas | last post by:
Hi all, From a word macro in VBA, I am trying to create a report in access DB. The report is based on a query with a parameter. I am using Set rpt = Application.CreateReport rpt.RecordSource =...
2
by: Roger | last post by:
Anyone know how to pass a parameter to a query via a report in Access 2003?
2
by: jasenpeters | last post by:
I'm not sure I understand the use of parameter queries and reports. I have a query that returns calculations for Categories. There are 6 Categories (A,B,C,D,E,F). There are also two Types of...
2
by: PotatoChip | last post by:
I am working in Access 2002 and I have been asked to create a form for a report based on a paramter query so that the user selects the department from a drop down list on the form, query runs and...
3
by: vljones | last post by:
I have a report with sub reports. The sub reports are query based. The queries perform a Count. Where no data exists in the table, no results are provided. Is there a way to populate the sub...
3
beacon
by: beacon | last post by:
Hi everybody, I'm trying to automate the creation of some Excel workbooks using the CopyFromRecordset method. However, the recordsets that I need to send to the Excel workbook are based off...
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: 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$) { } ...
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
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
marktang
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,...
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.