Results 1 to 4 of 4
  1. #1
    creyc is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Mar 2013
    Posts
    6

    Multiple dates per ID - only show those whose LATEST date at least certain amount old

    Intro:


    I have a list of locations that need maintaining if the last known maintenance date is either 12H old, or has never been maintained (null date). When maintenance is performed on any location the date is added to a table, along with its location.

    So far I have a simple database working fine, I can run a query and see all the locations and all their dates of last maintenance in one big list. By turning on "Totals" and setting the date field to "Last", I see only the latest maintenance date for each location, great so far.

    Now I want to further filter this down to show only those whose LATEST dates are at least 12H old. I add this to the criteria in the form
    Code:
    DateDiff("h",[MaintDate],Date())>12
    and of course, because I'm doing this wrong, get the error "Your query does not include the specified expression '....' as part of an aggregate function". I don't know what this error means, or how to achieve what I'm after. Do I need a second query to put my >12 hour criteria?

    Thanks!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Don't use DataDiff().

    Try criteria under the MaintDate field:

    <DateAdd("h",-12,Date())

    Be sure to change the Total row to 'WHERE'.
    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.

  3. #3
    creyc is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Mar 2013
    Posts
    6
    Quote Originally Posted by June7 View Post
    Don't use DataDiff().

    Try criteria under the MaintDate field:

    <DateAdd("h",-12,Date())

    Be sure to change the Total row to 'WHERE'.
    Thank you this suggestion works wonderfully.

    Yes, the date field does include time, as it's summed from [Date] + [Time]

    Would it be better to use Date() or Now()?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    If you want 12 hours from the current hour then I suggest Now() instead of Date()
    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. Query to show latest records
    By Conceptz in forum Queries
    Replies: 3
    Last Post: 05-24-2012, 01:01 PM
  2. Replies: 1
    Last Post: 02-17-2012, 04:43 PM
  3. Limit query to only show the latest record
    By marcustofeles in forum Queries
    Replies: 12
    Last Post: 10-05-2011, 08:06 AM
  4. Mixed dates - show only complete dates?
    By weeblesue in forum Queries
    Replies: 3
    Last Post: 10-27-2010, 02:15 PM
  5. Replies: 3
    Last Post: 09-29-2009, 07:08 AM

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