Results 1 to 7 of 7
  1. #1
    roarcrm is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jun 2014
    Posts
    27

    Query Design - Calculated Fields

    Hello all,



    I have a form layout as displayed here with a Task form embedded inside a Project form - each project can have many tasks and for each task the Time Used is subtracted from the total Hours Allocated which gradually decreases. What I want to do is to have a query set up that displays all projects with the Hours Remaining field displayed.

    I have tried to play about with this and the only time I got the hours remaining values to display in the query results it seemed to display multiple lines for every task rather than one line for the whole project. Can somebody point me in the right direction here? Many thanks in advance.

    Click image for larger version. 

Name:	form.png 
Views:	11 
Size:	28.8 KB 
ID:	16977

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    First, create a query that sums the TIMESPENT field by the PK/FK related field between your form/subform. This will give you the total time used for each project.

    Then create another query based on the table driving your 'main' form link it to the secondary query you created through the PK/FK field you should be able to see the time alloted and time used, then you can calculate the time remaining.

  3. #3
    roarcrm is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jun 2014
    Posts
    27
    Quote Originally Posted by rpeare View Post
    First, create a query that sums the TIMESPENT field by the PK/FK related field between your form/subform. This will give you the total time used for each project.

    Then create another query based on the table driving your 'main' form link it to the secondary query you created through the PK/FK field you should be able to see the time alloted and time used, then you can calculate the time remaining.
    Thanks for that! I understand what you mean, sorry to sound daft but how would I create the query to sum the Time Spent field? The PK in the Project table is ProjectIdentifier which is the FK in the Task table. The PK in the Task table is TaskIdentifier.

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    it's called an aggregate query. Look for the sigma button in your query design (looks like a capital E). It will add a row to your query design area called TOTAL or TOTALS the default is GROUP BY, change that to SUM, when included with the FK field it will sum all the time used for the project.

  5. #5
    roarcrm is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jun 2014
    Posts
    27
    Quote Originally Posted by rpeare View Post
    it's called an aggregate query. Look for the sigma button in your query design (looks like a capital E). It will add a row to your query design area called TOTAL or TOTALS the default is GROUP BY, change that to SUM, when included with the FK field it will sum all the time used for the project.
    Thanks! How do I include this in the second query?

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I told you how in the first post.

    You have two tables one is your 'main' one is your 'sub'
    Similar to your form constrution, your 'main' form employs the 'main' table, the subform employs the 'sub' table.

    You aggregate the data in the 'sub' table using the FK (foreign key) of your main table.
    Once this query is written and correctly summing your values for each FK then create a SECOND query including your 'main' table and the query you've just written, link the table and query together using the PK/FK (primary key/foreign key) link.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,970
    or build a report and use report Sorting & Grouping features with aggregate calcs in group footer sections.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 7
    Last Post: 03-16-2014, 06:59 PM
  2. Replies: 12
    Last Post: 10-01-2013, 12:59 PM
  3. Replies: 2
    Last Post: 01-28-2013, 11:32 AM
  4. Replies: 2
    Last Post: 06-10-2012, 01:10 PM
  5. Replies: 1
    Last Post: 05-04-2011, 03:51 PM

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