Results 1 to 6 of 6
  1. #1
    riggsdp is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2014
    Posts
    25

    Getting correct date from query results

    I need to figure out an event's starting date based on the last time the item was delivered.



    For example, if an item is due monthly, there may be 40 previous deliveries, but I only want to find the last delivery date so I can add a month to that date for the current delivery.

    My very first delivery has its due date calculated by getting the start date of the delivery or task order using DLookup, then calculating the due date through a SetDueDate function.

    Code:
    startDate = DLookup("Start_Date", "tblDeliveryTaskOrders", "Task_ID = " & Forms!frmDeliveriesReceived!frmDeliveriesReceived_Subform.Form!Delivery_Task_Order)
    SetDueDate = FindDueDate(eventDue, startDate)
    After it is delivered, the next delivery needs to get the previous delivery date from the delivery table with the same Relate_ID:

    I have the following query (qryGetLastDelivered) to get the last date for each set of items:

    Code:
    SELECT tblDeliveriesReceived.Relate_ID, Max(tblDeliveriesReceived.Date_Due) AS [Total Of Date_Due]FROM tblDeliveriesReceived
    GROUP BY tblDeliveriesReceived.Relate_ID;
    So, how do I get the start date I need from the query results where
    Code:
    "Relate_ID = " & Forms!frmDeliveriesReceived!frmDeliveriesReceived_Subform.Form!Relate_ID)
    Thanks in advance.

  2. #2
    riggsdp is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2014
    Posts
    25
    Modified my query to this and it gets the date I need, now just need to pass that date to my code:

    Code:
    SELECT tblDeliveriesReceived.Relate_ID, Max(tblDeliveriesReceived.Date_Due) AS [Total Of Date_Due]FROM tblDeliveriesReceived
    GROUP BY tblDeliveriesReceived.Relate_ID
    HAVING (((tblDeliveriesReceived.Relate_ID)=[Forms]![frmDeliveriesReceived]![frmDeliveriesReceived_Subform].[Form]![Relate_ID]));

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    if you are saying you want to look up the 'start date' from two different tables under different conditions.
    1. An 'order' has been placed (something exists in tbldeliverytaskorders) but no deliveries have ocurred (nothing in table tblDeliveriesReceived)
    2. An 'order' has been placed and deliveries exist

    you could do something in your function like

    Code:
    if dcount("*", "tbldelivereisreceived", "[Relate_ID] = " & forms!frmdeliveriewsreceived!frmdeliveriesrecieved_subform.form!relate_ID) = 0 then
        'do what you're going to do if nothing exists in the tbldeliveriesreceived table
    else
        'do what you're going to do if something exists in the tbldeliveriesreceived table
    endif
    I don't know how well this would work if you're using a continuous bound subform (I don't use bound forms). in the first portion of the IF statement you could have your existing code startdate = blah/setduedate (eventdue, startdate), in the second portion you could just lookup the maximum date with dmax("date_due", "tbldeliveriesreceived", "[Relate_ID] = " & <form qualifier> )

  4. #4
    riggsdp is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2014
    Posts
    25
    Thanks, I already have that part taken care of, but what I need is how to pass the date result from the query back to my code - which is what would be done if a delivery already exists.

    For example: startDate = result from qryGetLastDelivered

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I think I addressed that

    startdate = dmax("[due_date]", "tblDeliveriesReceived", "[Relate_ID] = " & [Forms]![frmDeliveriesReceived]![frmDeliveriesReceived_Subform].[Form]![Relate_ID])

    you don't need the query qrygetlastdelivered at all if you use the dmax function

  6. #6
    riggsdp is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2014
    Posts
    25
    Okay, now I understand! Thanks and will try it out.

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

Similar Threads

  1. Query Results on an 'as at' date
    By roarcrm in forum Queries
    Replies: 3
    Last Post: 09-18-2014, 03:33 AM
  2. Replies: 5
    Last Post: 09-12-2014, 06:41 AM
  3. Replies: 1
    Last Post: 02-05-2013, 12:15 PM
  4. Replies: 3
    Last Post: 07-13-2012, 09:18 AM
  5. Replies: 9
    Last Post: 06-26-2011, 09:14 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