DataBase - Determine final status of detail records related to a master record
Asked By Annette
01-Mar-08 11:59 AM
I have two tables - PO and PODetail. The PO table tracks such things
as date, po number, vendor, etc. The PODetail table links to the PO
table and contains detail information such as item, account number,
quantity and paid status. If there is a PO with 5 PODetails, each
entry in the detail can have it's own paid status. For example the PO
123 has 5 details and 4 have a paid status of "yes" and 1 has a paid
status of "no".
I have a query that lists all PO's and their status. If a PO has any
PODetail records that has at lease one paid status of "NO", I would
like the query that lists all PO's to list the status of unpaid. If
all the PODetail records are paid, then the PO status would be paid.
How can I parse the PODetail records to determine the final status of
PAID or UNPAID in the PO query?
PODetail.PODetailID
(1)
PODetail
(1)
Report
(1)
PaidStatus
(1)
Fa174a12c771
(1)
Subqueries
(1)
B3fe
(1)
POID
(1)
John Spencer replied...
Post the SQL of your query. (Menu View: SQL).
You can use an exists clause to determine if any one of the detail records
has a paid status of No.
Assumption: You are using a Yes/No field for the Paid Status
You can use a calculated field with a subquery
Field: Paid: EXISTS(SELECT * FROM PODetail WHERE [PaidStatus] = False and
PODetail.[PO ID] = PO.[PO ID])
That will return True (-1) if the PO has any detail record that is not paid
and zero if there is no such record.
If you need to see the words Paid or Unpaid you can show that in the query
or use the format property of a control in a report (or on form). You could
also use something like this in a query.
Field: Paid: IIF(EXISTS(SELECT * FROM PODetail WHERE [PaidStatus] = False
and PODetail.[PO ID] = PO.[PO ID]),"Unpaid","Paid")
--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
.
Allen Browne replied...
Use a subquery to determine if there are any related records where the Paid
field is unchecked.
This example assumes the 2 tables are joined on a field name POID:
SELECT PO.*
FROM PO
WHERE EXISTS
(SELECT PODetail.PODetailID
FROM PODetail
WHERE (PODetail.POID = PO.POID)
AND (PODetail.Paid = FALSE));
If subqueries are new, here's an introduction:
http://allenbrowne.com/subquery-01.html
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
Count and Filter Result DataBase My report has = Count(*) in the group header and I want to filter the results. Report Example: IDnumber Group Header Total of Reports Last Name First Name Idnumber 2 Smith Joe show the records of reports with the total of 4 or more. Access Reports Discussions Report (1) DateDiff (1) Ccumodsactionsother (1) Ccusanctionsother (1) Dateofreport (1) Reviewdate (1) Sonya (1) Unit (1) Try this in the query used as source for the report - -- SELECT [Last Name], [First Name], [Idnumber], Count([Idnumber]) AS [Total of Reports] FROM YourTable WHERE current code for my query. Where would I put the below infromation? SELECT [Minor Disciplinary Report].Last, [Minor Disciplinary Report].First, [Minor Disciplinary Report].IDnumber, [Minor Disciplinary Report].Unit, [Minor Disciplinary Report].Dateofreport, [Minor Disciplinary Report].[Gpsanction 1], [Minor Disciplinary Report].[Asddsanctions 1
Weighted Calculations DataBase I am trying to total an aggregate function in a report. Here is the basics. UnitIn- UnitOut - Yield - WtYield 10100 - 10000 - 99.01% - 90.01% 2000 UnitOut / sum([UnitOut]) = sum([WtYield]) does not work. These calculations are taking place in a report. I tried to make it happen in a query, but due to the group by to show all the proper fields (not shown here in interest of brevity) for the report it does not sum up the LBSProd properly. Is there a way to remove the Group By in the query, and still have the data show in a report perhaps? Any ideas? Access Reports Discussions LBSProd (1) ProdWtSub (1 Report (1) TotalTime (1) WtYield (1) UnitOut (1) UnitIn (1) Pounds (1) Post the SQL of all, copy, and paste in a post. - - Build a little, test a little. SELECT [Prod Report Master Data].Date, [Prod Report Master Data].[ITEM No], [Prod Report Master Data].Brand, [Prod Report Master Data].Description, [Prod Report Master Data].[Line#], [Prod Report
it posted. I have tried over and over again, various combinations, names, and placements within report and sub-report footers, etc. for these two problems, but am unable to come up with the correct can help me. I am trying to achieve the Yearly Bank Balance. I have, a report in which I first have a Beginning Balance Bank Header, nothing is in it expcept Control Source of = [Abegbal]+[txtincsum]. I get the total I need when I run the report. Also in the detail section, I have subrpt_expense_yearly. In this sub-report, I have a total expense. Name [TxtExpenseSum] Control Source = Sum([CkAmt]) Again, I get the total I need when I run the report. When I first started a smaller version of this project, I was instructed to put in the detail section: two text boxes, one containing = iif([sub_report_expense_yearly].[report].[has data].[sub_report_expense_yearly].[txtExpenseSum], 0) and another with = iif[sub_report_income_yearly].report.[has data].[txttotalassets], 0]) To obtain the ending balance, I have placed the following in
Limit Records Shown Per Report DataBase Question I use a report to show all systems located at a specific customer. When a customer has more than 20 systems, I would like a new report to start with all the same information in the header, etc. Any suggestions?? I am with header repeated on each page. UNTESTED UNTESTED UNTESTED In your query that feeds the report add field - - ZZZ: 1 Use Ranking in a Group in follow-on query with \ 20 post helpful to you? Reply Top Tia 2 / 3 / 2010 8:39 AM PST My report is set up with all the header information on the report and then all the systems are listed on subreport. They are connected through Customer ID I place the code in the query for the subreport or the query for the report??? Click to show or hide original message or reply text. Was this post helpful to DoCmd.OpenReport (1) DoCmd.OutputTo (1) Access 2007 (1) VBA (1) RichTextFormat (1) BartS1Report (1) Report (1) AcViewPreview (1) This has one short coming as the first page will only have
Errors in Report total fields DataBase I have an Invoice Report. It draws it is data from two forms. One is the implies, providing client data the print invoice main forma nd that is where the fieldnames come from for the report. A button on the second form opens a preview of the invoice report. I have checked and rechecked the field names and I cannot find an error. I I need to give you more info. Here is what I am getting on the Report. Invoice report has 3 subreports: time, expense and payments. Invoice Report Total Due field . . . Was: Forms![Print Invoice]![Total Expenses]+Forms![Print Invoice]![Total Hourly Billings loads for Forms!Clients!Clients Subform!Total Many thanks, Scott B Access Reports Discussions SubrptControlName.Report.HasData (1) Invoice.PaymentTotal.HasData (1) Invoice.ExpenseTotal.HasData (1) Invoice.PaymentTotal (1) Invoice.ExpenseTotal