Hi, I have a relatively simple database consisting of 3 Tables that are the same, WH-Budget(Master), Details1, Details2. WH-Budget is master to details1 and details1 is master to details2.
The Master is set out as:

And detail1 is:

And detail2 is:

The purpose of my Database is to be a budget planner for a project. The relationships work fine :
[WH-Budget].[WBS Element]-->details1.[Parent Element]
details1.[WBS Element]-->details2.[Parent Element]
and [WH-Budget].[WBS Element] is the [Master Element] for details2
The part i am stuck on is calculating the fields in the database. I need all the fields in the Master table to be calculated from the 2 detail pages, so i wrote this select query:
Code:
SELECT [WH-Budget].ID AS ID, [WH-Budget].[WBS ELEMENT] AS [WBS ELEMENT], Sum([DETAIL1].[Baseline Budget]+[DETAIL2].[Baseline Budget]) AS [Baseline Budget], Sum([DETAIL1].[Revised Cost]+[DETAIL2].[Revised Cost]) AS [Revised Cost], Sum([DETAIL1].Variance+[DETAIL2].Variance) AS Variance, Sum([DETAIL1].Ordered+[DETAIL2].Ordered) AS Ordered, Sum([DETAIL1].Invoiced+[DETAIL2].Invoiced) AS Invoiced, Sum([DETAIL1].Actual+[DETAIL2].Actual) AS Actual
FROM ([WH-BUDGET] INNER JOIN DETAIL1 ON [WH-BUDGET].[WBS ELEMENT]=DETAIL1.Parent) INNER JOIN DETAIL2 ON (DETAIL1.[WBS ELEMENT]=DETAIL2.Parent) AND (DETAIL1.Parent=DETAIL2.Master)
GROUP BY [WH-Budget].[WBS ELEMENT], [WH-Budget].ID;
This only works if there is one row for each element in the detail pages, so the query is obviously wrong
in the example above there are many detail2 records related to fewer detail1 and master records. I just cant get the calculations correct. I'm eventually running this through aspmaker to make a web based budget planner. Please help, i refuse to give up but honestly iv been on this for over 200hrs