Results 1 to 3 of 3
  1. #1
    rjgriffin46 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2014
    Location
    New Jersey
    Posts
    128

    Getting Latest Date from One Table Relative to Date in Another Table

    In our Kids Feeding database, there are the following tables:


    1. Site Changes. Fields:
      1. Site Number
      2. Meal Quantity
      3. Effective Date (for the meal quantity)

    2. Delivery. Fields:
      1. Delivery Date
      2. Serving Start Date (the 1st date the meals delivered on the Delivery Date will be served)
      3. Number of Serving Days (how many days worth of meals are delivered)

    In the situation to be addressed, 5 days worth of meals are delivered once a week to each site. The delivery is done on Thursday and the meals are for the following Monday through Friday.
    There can be multiple site change records for any given site. An example is that one site requires 125 meals Monday through Thursday and 120 on Friday. As it stands now, and subject to future enhancement, a Site Change record must be entered for each meal count change. So for example for the week of Monday, 10/7 to Friday, 11/October there would be the following site change records:

    Site Number Meal Quantity Effective Date
    1 125 10/7/19
    1 120 10/11/19






    I have a query that generates a record for each serving day for a delivery, so in this example, for a Thursday 10/3/19 delivery, there would be the following 5 records in the query recordset:
    Serving Date
    10/07/19
    10/08/19
    10/09/10
    10/10/19
    10/11/19











    I next need to generate another query that has the latest meal quantity for each of the 5 serving dates for each site. In this case the resulting recordset should be:

    Site Number Meal Quantity Serving Date
    1 125 10/07/19
    1 125 10/08/19
    1 125 10/09/19
    1 125 10/10/19
    1 120 10/11/19











    After some thought and a very brief search I'm thinking that a DMAX expression might work for this. This is a pretty small database with only a couple of users so performance shouldn't be an issue. Although I don't think a factor, this is the database about which I'd previously posted is deployed an has been running with a single read only front end via Citrix without any apparent problem for several months.

    As always, I'm appreciative of everyone's ideas and guidance, especially if you can point to some examples where something like this has been done.



    Thanks

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    you would need to use DMax and Dlookup to achieve what you want, better to use a subquery, or special join

    if data volumes are small, use a subquery

    Code:
    SELECT SiteNumber, ServingDate, (SELECT TOP 1 MealQuantity FROM tblChanges WHERE EffectiveDate<=ServingDate ORDER BY EffectiveDate Desc) AS Meals
    FROM QryServingDates

  3. #3
    rjgriffin46 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2014
    Location
    New Jersey
    Posts
    128
    Thank you Ajax. This looks quite promising.

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

Similar Threads

  1. Replies: 3
    Last Post: 03-17-2017, 08:52 AM
  2. Replies: 2
    Last Post: 05-12-2016, 07:46 AM
  3. Replies: 3
    Last Post: 01-06-2016, 07:42 PM
  4. Replies: 1
    Last Post: 11-16-2014, 09:10 AM
  5. Replies: 7
    Last Post: 01-21-2014, 11:35 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