Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25
  1. #16
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Did you follow my suggestion in posts 9 and 14?
    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.

  2. #17
    zipaway is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2014
    Posts
    53
    Quote Originally Posted by June7 View Post
    Link the two tables in query on the two common fields.
    Click one field and hold then drag to the corresponding field in other table. Then click the link line and set the join type.
    Repeat for the other pair.
    I think I am getting somewhere. I have this now.

    Click image for larger version. 

Name:	Capture.PNG 
Views:	7 
Size:	18.5 KB 
ID:	17549


    UPDATE ShipDeliveryDates INNER JOIN Change_Orders_Dates ON (ShipDeliveryDates.ComponentNumber = Change_Orders_Dates.ShipmentNumber) AND (ShipDeliveryDates.Project_Number = Change_Orders_Dates.Project_Number) SET ShipDeliveryDates.Sched_Ship_Date = [Change_Orders_Dates].[New_Sched_Ship_Date], ShipDeliveryDates.Sched_Ship_Date = [Change_Orders_Dates].[New_Sched_Delivery_Date];

    When I run it though I get an error "Duplicate output destination 'ShipDeliveryDates.Sched_Ship_Date'." and it does nothing.

  3. #18
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Why do you have Sched_Ship_Date field in the grid twice? Should one of those be Sched_Delivery_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.

  4. #19
    zipaway is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2014
    Posts
    53
    Quote Originally Posted by June7 View Post
    Why do you have Sched_Ship_Date field in the grid twice? Should one of those be Sched_Delivery_Date?
    Wow I can't believe I didn't spot that! Thanks so much. It is kinda working now but if I have two change orders for the same project it updates using the first set (Should pick the last entered change order). How would I go about only updating with the maximum change_order number for a project?

    Click image for larger version. 

Name:	Capture.PNG 
Views:	7 
Size:	12.3 KB 
ID:	17551

  5. #20
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Now that gets nasty tricky.

    This approach abandons the table join.

    UPDATE ShipDeliveryDates SET Sched_Ship_Date = DMax("New_Sched_Ship_Date", "[Change_Orders_Dates]", "Project_Number=" & [Project_Number] & " AND "ShipmentNumber=" & [ShipmentNumber]),
    Sched_Delivery_Date = DMax("New_Sched_Delivery_Date", "[Change_Orders_Dates]", "Project_Number=" & [Project_Number] & " AND "ShipmentNumber=" & [ShipmentNumber]);
    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.

  6. #21
    zipaway is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2014
    Posts
    53
    Quote Originally Posted by June7 View Post
    Now that gets nasty tricky.

    This approach abandons the table join.

    UPDATE ShipDeliveryDates SET Sched_Ship_Date = DMax("New_Sched_Ship_Date", "[Change_Orders_Dates]", "Project_Number=" & [Project_Number] & " AND "ShipmentNumber=" & [ShipmentNumber]),
    Sched_Delivery_Date = DMax("New_Sched_Delivery_Date", "[Change_Orders_Dates]", "Project_Number=" & [Project_Number] & " AND "ShipmentNumber=" & [ShipmentNumber]);
    Hmm I get the following error running the above update query.

    Click image for larger version. 

Name:	Capture.PNG 
Views:	7 
Size:	7.6 KB 
ID:	17555

  7. #22
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Sorry, extra " mark before ShipmentNumber. Fix both DMax expressions to:

    " AND ShipmentNumber=" &
    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.

  8. #23
    zipaway is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2014
    Posts
    53
    Quote Originally Posted by June7 View Post

    UPDATE ShipDeliveryDates SET Sched_Ship_Date = DMax("New_Sched_Ship_Date", "[Change_Orders_Dates]", "Project_Number=" & [Project_Number] & " AND ShipmentNumber=" & [ShipmentNumber]),
    Sched_Delivery_Date = DMax("New_Sched_Delivery_Date", "[Change_Orders_Dates]", "Project_Number=" & [Project_Number] & " AND ShipmentNumber=" & [ShipmentNumber]);
    Hmm it doesn't seem to do anything. For some reason it's saying it will update all records in the database, I click yes and then nothing happens. I am trying to follow this SQL update query and I understand it for the most part but when you are doing DMax what is it finding the maximum of? It should be finding the max change_number.

  9. #24
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Yes, it will update all records because there is no filter criteria for the UPDATE. Should not be an issue. Don't know why didn't work.

    These DMax expressions should find the maximum (most recent) date values for each ShipmentNumber/Project_Number pair as specified in the criteria. Don't you want the most recent dates? Oh wait, the latest change order could be to a date earlier than dates of previous changes. Rats!%*%$^. If that is the case, this gets worse because need to use the maximum change_number as criteria to select record from Change_Orders_Dates.

    The following query should return the latest Change_Orders_Dates record for each ShipmentNumber/Project_Number.

    SELECT * FROM Change_Orders_Dates WHERE Change_Number IN (SELECT Max(Change_Number) AS CN FROM Change_Orders_Dates GROUP BY ShipmentNumber, Project_Number);

    Can try using that query as the source for the date updates instead of the Change_Orders_Dates table. However, if I remember correct, will generate a 'non-updatable dataset' error because of the aggregate query.

    So, if that doesn't work, try:
    SELECT * FROM Change_Orders_Dates WHERE Change_Number = DMax("Change_Number", "Change_Orders_Dates", "Project_Number=" & [Project_Number] & " AND ShipmentNumber=" & [ShipmentNumber]);

    I said this would be nasty tricky. But really, instead of updating table, should just use that query in a report.
    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.

  10. #25
    zipaway is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2014
    Posts
    53
    Quote Originally Posted by June7 View Post
    Yes, it will update all records because there is no filter criteria for the UPDATE. Should not be an issue. Don't know why didn't work.

    These DMax expressions should find the maximum (most recent) date values for each ShipmentNumber/Project_Number pair as specified in the criteria. Don't you want the most recent dates? Oh wait, the latest change order could be to a date earlier than dates of previous changes. Rats!%*%$^. If that is the case, this gets worse because need to use the maximum change_number as criteria to select record from Change_Orders_Dates.

    The following query should return the latest Change_Orders_Dates record for each ShipmentNumber/Project_Number.

    SELECT * FROM Change_Orders_Dates WHERE Change_Number IN (SELECT Max(Change_Number) AS CN FROM Change_Orders_Dates GROUP BY ShipmentNumber, Project_Number);

    Can try using that query as the source for the date updates instead of the Change_Orders_Dates table. However, if I remember correct, will generate a 'non-updatable dataset' error because of the aggregate query.

    So, if that doesn't work, try:
    SELECT * FROM Change_Orders_Dates WHERE Change_Number = DMax("Change_Number", "Change_Orders_Dates", "Project_Number=" & [Project_Number] & " AND ShipmentNumber=" & [ShipmentNumber]);

    I said this would be nasty tricky. But really, instead of updating table, should just use that query in a report.

    That first query worked!!! I did like you said and used the earlier update query with the new selection query and now it's working as it should be without even updating all the rows.

    You are an access genius! I sincerely thank you for all your help. I am just putting the final wraps on this access project hopefully I don't have to pester you anymore .

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 09-06-2013, 11:52 AM
  2. Replies: 7
    Last Post: 03-21-2013, 09:43 AM
  3. Replies: 3
    Last Post: 09-16-2012, 10:20 AM
  4. Replies: 0
    Last Post: 05-21-2012, 11:54 PM
  5. Replies: 6
    Last Post: 05-10-2012, 08:20 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