?
Solved

Access 2007 - help on a complex subreport query

Posted on 2011-02-15
7
Medium Priority
?
376 Views
Last Modified: 2012-05-11
In an Access 2007 application, I have a report that has two sub reports.  The parent report is opened from code and is filtered down to showing data about 1 project and therefore has 1 ProjectID.  I have that ProjectID tied to the ProjectID of the first subreport to filter it's data down to show only that data corresponding to the project of the parent report.  The second report however is giving me problems as it is a lot more complex of a query.  Below is shown a query that I have built in Access query builder that I have finally gotten to show the data correctly for 1 project.  Notice the WHERE clause...

WHERE tbContractProject.ProjectID IS NULL OR tbContractProject.ProjectID = 4

I want to use this query to build a report that will act as my second subreport and I need the 4 in the WHERE clause to change to the ProjectID of the project loaded into the parent report.  I'm not sure how to go about doing this.

Any help would be greatly appreciated.
I need the 4 to be changed to the ProjectID of the parent report
SELECT tbExpenditureType.ExpenditureType, SUM(IIf(IsNull(tbExpenditureLedger.Amount),0,tbExpenditureLedger.Amount)) AS Amount
FROM ((tbExpenditureType LEFT JOIN tbFundingSourceFundingTypeExpenditureType ON tbExpenditureType.ExpenditureTypeID = tbFundingSourceFundingTypeExpenditureType.ExpenditureTypeID) LEFT JOIN tbExpenditureLedger ON tbFundingSourceFundingTypeExpenditureType.FundingSourceFundingTypeExpenditureTypeID = tbExpenditureLedger.FundingSourceFundingTypeExpenditureTypeID) LEFT JOIN tbContractProject ON tbExpenditureLedger.ContractProjectID = tbContractProject.ContractProjectID WHERE tbContractProject.ProjectID IS NULL OR tbContractProject.ProjectID = 4
GROUP BY tbExpenditureType.ExpenditureType

Open in new window

0
Comment
Question by:JosephEricDavis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 34900990
Does the query work when run alone?

Post a sample of this database.
Post a graphic clearly showing the exact output you are expecting.

Sample database notes:
1. Back up your database(s).
2. Combine the front and back ends into one database file.
3. Remove any startup options, unless they are relevant to the issue.
4. Delete any objects that do not relate directly to the issue.
5. Remove any references to any "linked" files (files outside of the database, Images, OLE Files, ...etc)
6. Remove any references to any third party Active-x Controls (unless they are relevant to the issue)
7. Remove, obfuscate, encrypt, or otherwise disguise, any sensitive data.
8. Compile the code. (From the database window, click: Debug-->Compile)
9. Run the compact/Repair utility.
10. Remove any Passwords and/or security.
11. Post explicit steps to replicate the issue.
12. Test the database before posting.

In other words, ...post a database that we can easily open and immediately see the issue.


JeffCoachman
0
 
LVL 11

Accepted Solution

by:
RgGray3 earned 1000 total points
ID: 34901019
I would use a replaceable paramater,  hooked to a global var...  to pass the data to the query.

In a standard module... create a public var and a function to retrieve it

Public gintProjectID as Integer    (or your datatype)

Public Function GetProjectID() as Integer
    GetProjectID = gintProjectID
End Function

You criteria in your query becomes

WHERE tbContractProject.ProjectID IS NULL OR tbContractProject.ProjectID = GetProjectID()

Set gintProjectID =.... in a routine that you use to open the report  or in a section of your report

If I knew more about the app I could make a better suggestion on the timing
0
 
LVL 31

Assisted Solution

by:Helen Feddema
Helen Feddema earned 1000 total points
ID: 34901032
If I understand what you want, this might work:

WHERE tbContractProject.ProjectID IS NULL OR tbContractProject.ProjectID = Parent!ProjectID

0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 31

Expert Comment

by:Helen Feddema
ID: 34901041
Or you could use the full syntax:

Reports![rptName]!ProjectID
0
 
LVL 11

Expert Comment

by:RgGray3
ID: 34901125
Is this subreport only run as a subreport from this report?
0
 
LVL 7

Author Closing Comment

by:JosephEricDavis
ID: 34907300
Thanks guys, these were good suggestions.
0
 
LVL 11

Expert Comment

by:RgGray3
ID: 34907703
Glad to help

0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question