Solved

Access 2007 - help on a complex subreport query

Posted on 2011-02-15
7
358 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
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 250 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 250 total points
ID: 34901032
If I understand what you want, this might work:

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

0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

860 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