Results 1 to 9 of 9
  1. #1
    chuckdarwin is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jan 2018
    Posts
    15

    Old Farmer needs help with a date query

    I am learning as I go here but i just cant figure this one out

    I have table listing Insect Broods. there are two fields I am working with and they are [Seed Date] and [POP Est]
    I am strying to sum all records within 1 week date ranges to provide available populations

    I created the following query

    SELECT Sum(Broods.[POP Est]) AS [SumOfPOP Est], Broods.[Seed Date], Broods.[Brood ID], Broods.Species
    FROM Broods
    GROUP BY Broods.[Seed Date], Broods.[Brood ID], Broods.Species


    HAVING (([Seed Date]>=DateAdd("d",-17,Date())) AND ((Broods.Species)='House Cricket'));

    That is to give me a sum of all crickets from 17 days after seed
    I intend to furthur filter this down to only sum the populations from 10 days to 17 days but baby steps here i cant get past this first one


    Problem is instead of totaling the values contained in [POP Est] it is displaying all the records.

    Can someone see what i am doing wrong

    thanks in advance

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    The records will show depending on your grouped fields - one of which is the date. This should be a non-display field. You also do not need to display the species as they will all be the same.

  3. #3
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Try changing the Having to a WHERE clause.

    Having will apply the criteria after the grouping is done, I think you need it before.
    Code:
    SELECT Sum(Broods.[POP Est]) AS [SumOfPOP Est]
    FROM Broods
    WHERE (([Seed Date]>=DateAdd("d",-17,Date())) AND ((Broods.Species)='House Cricket'))
    
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    chuckdarwin is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jan 2018
    Posts
    15
    That worked like a charm

    Now just gotta figure out how to filter by max age

  5. #5
    chuckdarwin is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jan 2018
    Posts
    15
    So i tried adding in other filter using the same format and now it generates zero results.

    SELECT Sum(Broods.[POP Est]) AS [SumOfPOP Est]
    FROM Broods
    WHERE (((Broods.[Seed Date])>=DateAdd("d",-24,Date())) AND ((Broods.Species)='House Cricket') AND ((Broods.[Seed Date])<=DateAdd("d",-31,Date())));


    Am i missing something here

    I apologize i am learning as i go here

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    "Sum" denotes totaling, you can't just type it in. Click on the totals icon at the top in query design, then select sum from the total line.

  7. #7
    chuckdarwin is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jan 2018
    Posts
    15
    I dont understand I didnt change the Sum all i did was add the additional text saying

    AND ((Broods.[Seed Date])<=DateAdd("d",-31,Date())));

    What i am trying to do

    Seed date is the date eggs are placed in the icubator
    10 days later they hatch
    I need to run querys showing me the Total crickets that are 1 week 2 week ect all the way to 5 weeks

    I thought i was on the correct path am i wrong ?

  8. #8
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Date must be after 24 days ago and before 31 days ago! Ain't gonna happen. You can also use Between Date1 And Date2 for dates.

  9. #9
    chuckdarwin is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jan 2018
    Posts
    15
    ROFL I noticed that after. Been busy fixing everything and it works perfectly thank you all for you help

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

Similar Threads

  1. Replies: 2
    Last Post: 06-28-2017, 06:16 PM
  2. Replies: 2
    Last Post: 04-10-2017, 10:57 AM
  3. Replies: 6
    Last Post: 03-02-2016, 12:58 PM
  4. Replies: 3
    Last Post: 03-11-2014, 07:32 PM
  5. Replies: 3
    Last Post: 08-21-2012, 03:05 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