Results 1 to 10 of 10
  1. #1
    My User Name is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    5

    Master/Detail1/Detail2 - All Calculated.* Genius Required*

    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:

    Click image for larger version. 

Name:	master.jpg 
Views:	24 
Size:	49.5 KB 
ID:	8472
    And detail1 is:
    Click image for larger version. 

Name:	det1.jpg 
Views:	24 
Size:	86.1 KB 
ID:	8473
    And detail2 is:
    Click image for larger version. 

Name:	det2.jpg 
Views:	24 
Size:	104.1 KB 
ID:	8469
    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
    Attached Thumbnails Attached Thumbnails master.jpg  

  2. #2
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    You might want to re-think your design or provide more detail on your design. From what is displayed you have a lot of the same fields in each table. Read up on normalization it'll help. Also I've never found a good reason to use relationships at the table level. In my humble opinion your better off setting the relationships using queries.

  3. #3
    My User Name is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    5
    I was just experementing with the relationships, thats why the tab is open. This is goin to be used as a budget planner for a site relocation. The main table has the topic headers like, people, machinery. Then when the user clicks the little plus button they can add or view an item of machinery and even add details about that. im trying to make the amounts add up and display on the main tbale for each topic. I have researched database normalization in the past and done tutorials. I'v been programming for 10 years. I'v posted this question in at least 4 other forums in 4 months and no one gets it.

  4. #4
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    If you could post your actual table structure for each of those tables you might get additional help. Based on what I can see it looks like you have a lot of the same data elements in each table. That's a sure sign of a bad design. although it could look that way due to the relationships. I've never used them so no clue as to what is presented by your attachments. I've been designing Databases since 1991 I'll help as much as i can but need to understand your structure to help.

  5. #5
    My User Name is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    5
    This is a drill down, treeview, budget planner
    Click image for larger version. 

Name:	STRUCTURE.png 
Views:	25 
Size:	10.9 KB 
ID:	8476
    This is the structure, master, parent and WBS ELEMENT are text, all the rest are numeric

    WH-BUDGET | Details1 | Details2
    Baseline Budget = Baseline Budget + Baseline Budget

    +same for all numeric fields

    i'v uploaded my DB too, thanks for your help budgetDB.zip

    if you need any more info to advise me i will reply asap.

  6. #6
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    Looked at your tables and I think you need to rethink your design. Also the data doesn't make sense which is caused by your design. Here's my recommendation:

    Table WH-Budget
    whBudgetID AutoNumber PrimaryKey
    whBudgetDesc Text

    Table Detail1
    Detail1ID AutoNumber PrimaryKey
    whbudgetid number ForeignKey to wh-Budget table
    Detail1Desc Text

    Table Detail2
    Detail2ID AutoNumber PrimaryKey
    Detail1ID Number ForeignKey to Detail1
    Detail1Desc Text
    Baseline Numeric
    Revised Numeric
    Variance Numeric
    Ordered Numeric
    Invoiced Numeric
    Actual Numeric

  7. #7
    My User Name is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    5
    Hi, thanks for your great advice after thinking it over, it does seem a lot more logical. If i wanted to add an extra detail table would this be ok:

    Table WH-Budget
    whBudgetID AutoNumber PrimaryKey
    whBudgetDesc Text

    Table Detail1
    Detail1ID AutoNumber PrimaryKey
    whbudgetid number ForeignKey to wh-Budget table
    Detail1Desc Text

    Table Detail2
    Detail2ID AutoNumber PrimaryKey
    Detail1ID number ForeignKey to Detail1
    Detail2Desc Text

    Table Detail3
    Detail3ID AutoNumber PrimaryKey
    Detail2ID Number ForeignKey to Detail2
    Detail3Desc Text
    Baseline Numeric
    Revised Numeric
    Variance Numeric
    Ordered Numeric
    Invoiced Numeric
    Actual Numeric

    Am i right in thinking from here i would just call any tables i need with an sql select, then set the master/detail relationships?

  8. #8
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    Yep. The relationships can be set in the queries by using Joins.

  9. #9
    My User Name is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    5
    Im working on the sql now but im not sure its going to work because not all the [whbudget] records will go to detail3 some may just have detail1 record and thats it. Would this mean i need to include the other fields eg. baseline budget, variance, on all the detail tables?

  10. #10
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    Not necessarily. It's hard to analyze from here with table names detail1,detail2,detail3 Not sure what each is actually for. based on my understanding. I thought it was where the wHbudget was the category. Detail1 a sub category. Detail2 a sub category of detail1 and detail 3 the actual detail. Apparently that is inaccurate. Maybe you could explain what each detail table actually represents?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. sql . need a genius
    By kevinnice in forum Queries
    Replies: 5
    Last Post: 03-07-2012, 02:35 PM
  2. Replication. (Master and Dummy DBs)
    By OrangePie in forum Access
    Replies: 1
    Last Post: 07-28-2011, 03:10 PM
  3. Master file not updating
    By pmac in forum Access
    Replies: 3
    Last Post: 06-20-2011, 11:46 AM
  4. Master/Child between Subforms
    By Pilotwings_64 in forum Forms
    Replies: 3
    Last Post: 08-22-2010, 01:45 AM
  5. Replica/Design master
    By rudyp in forum Access
    Replies: 50
    Last Post: 03-23-2009, 05:52 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums