Results 1 to 6 of 6
  1. #1
    jaypoppin is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2011
    Posts
    13

    Most Recent Date Criteria Across Two Fields

    Hello,



    I need help with what seems to be a basic problem. I'm going to try to cut out all of the superfluous elements and explain it in the following way:

    Say I have a query which is pulling data (in memo form) that records different language I have used to summarize different cases I am involved in, in different reports that have been produced over the past several years.

    Some cases are summarized in several different reports, some cases are only summarized in one report. The main table in question assigns a unique ID number to each summary, recording what its a summary of (i.e. which case it summarizes, which it selects from another table), and which report it was in (which it selects from another table).

    Each report is dated, and so each summary is dated by proxy.

    It is easy for me to make a query that lists all summaries sorted first by the name of the case being summarized, and sorted second by the date of the report in which the summary appeared.

    What I would like to be able to do is the following: for every unique case name, I want to return only the most recent summary. I.e. I don't want to return multiple summaries for case names for which there are multiple summaries stored in the underlying table, but only the most recent one.

    I hope that wasn't too convoluted.

    Thanks,

    Jay

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Requires subquery or DMax.

    Build a query that joins tables so all related information is available. Then try another query:

    SELECT * FROM query1 WHERE ReportDate= DMax("ReportDate", "tablename", "CaseName='" & [CaseName] & "'");
    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
    jaypoppin is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2011
    Posts
    13
    Thanks, though I'm unable to tell if this works because when it runs it prompts me for a date.

    Let me try to re-explain.

    Say its all in one table:

    Case Name | Case Summary | Date

    Case 1 | Lorem ipsum dolor... | DateX
    Case 1 | Lorem ipsum dolor... | DateY
    Case 2 | Lorem ipsum dolor... | DateX
    Case 3 | Lorem ipsum dolor... | DateZ

    And I want to return only the most recent Case Summary for each unique Case Name. So, assuming X is more recent than Y is more recent than Z, I want to return the following:

    Case Name | Case Summary | Date

    Case 1 | Lorem ipsum dolor... | DateX
    Case 2 | Lorem ipsum dolor... | DateX
    Case 3 | Lorem ipsum dolor... | DateZ

    Is there a way to do this? (I might also be messing up what identifiers take [] and which don't in Access.)

    Thanks so much,

    Jay

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    The [] are used with table and field names. They are required if name contains spaces or special characaters or are reserved word.

    My example used ReportDate and CaseName as field names. Use your real field names, possibly:

    SELECT * FROM [your table or query name here] WHERE [Date]= DMax("[Date]", "[your table or query name]", "[Case Name]='" & [Case Name] & "'");
    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.

  5. #5
    jaypoppin is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2011
    Posts
    13
    So I used that code, but when I run the query I'm prompted to enter a parameter value for Date?

    Quote Originally Posted by June7 View Post
    The [] are used with table and field names. They are required if name contains spaces or special characaters or are reserved word.

    My example used ReportDate and CaseName as field names. Use your real field names, possibly:

    SELECT * FROM [your table or query name here] WHERE [Date]= DMax("[Date]", "[your table or query name]", "[Case Name]='" & [Case Name] & "'");

  6. #6
    jaypoppin is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2011
    Posts
    13
    For reference, the code is:

    SELECT *
    FROM [Case Summaries]
    WHERE [Date]= DMax("[Date]", "[Case Summaries]", "[Case Name]='" & [Case Name] & "'");

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

Similar Threads

  1. Choose the row with the MOST RECENT date
    By taimysho0 in forum Queries
    Replies: 1
    Last Post: 05-14-2012, 02:35 PM
  2. Display Most Recent Date
    By jsimard in forum Queries
    Replies: 2
    Last Post: 06-23-2011, 02:44 PM
  3. Get Recent Record without Id or date
    By pyog in forum Queries
    Replies: 5
    Last Post: 04-19-2011, 09:43 AM
  4. Replies: 1
    Last Post: 02-25-2011, 06:11 PM
  5. Replies: 4
    Last Post: 05-04-2010, 03:33 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