Solved

Access 2007 - help on a complex subreport query

Posted on 2011-02-15
7
340 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
Comment Utility
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
Comment Utility
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
Comment Utility
If I understand what you want, this might work:

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

0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 31

Expert Comment

by:Helen_Feddema
Comment Utility
Or you could use the full syntax:

Reports![rptName]!ProjectID
0
 
LVL 11

Expert Comment

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

Author Closing Comment

by:JosephEricDavis
Comment Utility
Thanks guys, these were good suggestions.
0
 
LVL 11

Expert Comment

by:RgGray3
Comment Utility
Glad to help

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now