Results 1 to 4 of 4
  1. #1
    rachello89 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    15

    Query Last Record as of Certain Date

    I have two tables: tblEnrollments and tblEnrollmentProduct. They are joined by the field EnrollmentID with a one to many relationship. An enrollment can have many enrollment products. I would like to design a query that searches for the last record as of a certain date. I know how to find the last record, but when I add a date criteria it doesn't match what I want to see. Anyone know how to solve this? I would appreciate your help! Below are the details of what I need.

    tblEnrollment fields: EnrollmentID, EnrollmentDate, and EnrollmentEndDate.
    tblEnrollmentProduct: EnProdID, EnrollmentID, EnrollmentProduct, StartDate, EndDate.



    For every EnrollmentID, I need to see the latest EnProdID where the StartDate is less than or equal to a date that I provide. The EnProdID would change if typed in a later or earlier date. For instance, Enrollment 5050 has EnProdIDs and StartDates of 8049, 1/26/2012; 8094, 2/1/2012; and 8151, 4/1/2012. If I type in 2/29/2012 or 3/12/2012, I want to see EnProdID 8094, and if I type 4/2/2012, I want to see 8151 next to enrollment 5050.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    It sounds like you want this:

    http://www.baldyweb.com/LastValue.htm

    You should be able to add a WHERE clause to the first to have it restrict to records before a given date.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    rachello89 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    15
    Thanks! Just what I needed.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 11-23-2011, 12:25 AM
  2. Date Record Entered
    By MikeDBMan in forum Access
    Replies: 6
    Last Post: 08-01-2011, 03:59 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: 4
    Last Post: 05-04-2010, 03:33 PM
  5. Replies: 2
    Last Post: 07-31-2009, 06:56 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