Results 1 to 12 of 12
  1. #1
    JensenQT is offline Novice
    Windows 11 Office 365
    Join Date
    Apr 2023
    Posts
    6

    using 'Max()' in an update query?


    So I'm trying to use an update query to update a due date field from table A, using the latest event date from table B per AutoID (table A) + A frequency (days).

    I've tried a few different ways but no closer, any suggestions?

    (I'm quite new to access and rarely touched update query)

    thanks.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    So give us a clue, what have you used?

    Show your sql, and relationship window at least?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    JensenQT is offline Novice
    Windows 11 Office 365
    Join Date
    Apr 2023
    Posts
    6
    Here is the relationship table thing.
    and the error.
    Attached Thumbnails Attached Thumbnails Screenshot 2023-04-05 122306.png   Screenshot 2023-04-05 122429.png  

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Firstly I think the order of your functions is incorrect.
    You need to get the Max date first, then use DateAdd(). You have it the other way around?

    Try using DMax() instead to get the date, then surround that with the DateAdd()

    Do it in stages, so you can check the results. Make it a Select query and when correct, change it to an update query.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    JensenQT is offline Novice
    Windows 11 Office 365
    Join Date
    Apr 2023
    Posts
    6
    I have tried the method you provided. Im not quite sure what to think about this new error?
    Click image for larger version. 

Name:	Screenshot 2023-04-05 135550.png 
Views:	17 
Size:	12.4 KB 
ID:	50051
    Click image for larger version. 

Name:	Screenshot 2023-04-05 135640.png 
Views:	17 
Size:	4.2 KB 
ID:	50052

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Right.
    Your Dmax() is not even attempting to use the correct syntax? God know what Access thinks that is.

    As I mentioned previously, get the data into separate columns. get the Max date first, then apply the DateAdd() in yet another columns and compare.

    You should be using the same criteria for the DMax(), that you are using for the update, which you said was you EquipmentInventoryID ?, else you will get any old date.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    JensenQT is offline Novice
    Windows 11 Office 365
    Join Date
    Apr 2023
    Posts
    6

    Arrow Alternate Route:

    Im trying an alternative route, as I am not understanding why certain expressions and functions work with some things and not others.

    I have create a Qry to Find the latest Date of a list of events and add months with a frequency.
    This works fine.
    Click image for larger version. 

Name:	Screenshot 2023-04-06 101656.png 
Views:	10 
Size:	20.0 KB 
ID:	50060Click image for larger version. 

Name:	Screenshot 2023-04-06 101714.png 
Views:	10 
Size:	27.2 KB 
ID:	50062

    But then when trying to use this in an update Qry it breaks and picks one date.
    Click image for larger version. 

Name:	Screenshot 2023-04-06 102748.png 
Views:	10 
Size:	16.3 KB 
ID:	50061Click image for larger version. 

Name:	Screenshot 2023-04-06 102806.png 
Views:	10 
Size:	7.6 KB 
ID:	50063

    anyone have any idea why its doing this? and if you do maybe explain it to me?

    thanks.

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Well, your field that you want to use appears to be called Due ?

    Show the SQL code.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    JensenQT is offline Novice
    Windows 11 Office 365
    Join Date
    Apr 2023
    Posts
    6
    Code:
    SELECT QryMaxEventDate.EquipmentInventoryID, DateAdd("m",[Frequency],[MaxOfDate_of_Event]) AS Due
    FROM TblEquipment_Inventory INNER JOIN QryMaxEventDate ON TblEquipment_Inventory.EquipmentInventoryID = QryMaxEventDate.EquipmentInventoryID;
    Code:
    UPDATE QryDateAutoFill INNER JOIN TblEquipment_Inventory ON QryDateAutoFill.EquipmentInventoryID = TblEquipment_Inventory.EquipmentInventoryID SET TblEquipment_Inventory.Calibration_Due_Date = [MaxOfDate_of_Event];

  10. #10
    JensenQT is offline Novice
    Windows 11 Office 365
    Join Date
    Apr 2023
    Posts
    6
    Quote Originally Posted by Welshgasman View Post
    Well, your field that you want to use appears to be called Due ?

    Show the SQL code.
    I did have it set to 'Due' but I had to reopen it and was set back to the old one, it still produces the same result with 2/12/2022

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    OK, as I mentioned, I generally have to do this manually, but make it a select query and bring in the due date.

    If you have it correct in the Select query, then the update should work.

    Else upload the DB so someone can have a look. I only have 2007, so I might not be able to do that, but other members can.

    You cannot possibly use MaxOfDate_of_Event as that is before you add your Frequency?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  12. #12
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    RE post 7. If the frequency value being used is 2 and it appears your max month value is 10, then without criteria you will add 2 months to 10 months and all dates will be the same. Not sure where the 2 and 2022 comes from. You might have to use a subquery to get the max of a value but I'm not seeing how that result would apply to so many different dates. IMO, your first error is because it's not a Totals query. The update error means you are trying to update a field to something that the field cannot accept, be that Null, or strings instead of numbers (or vice versa) - something along those lines.

    You haven't shown the relationships window, you've shown a query design view. Ribbon>Database Tools>Relationships
    I think that would help to figure things out.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 4
    Last Post: 03-09-2022, 11:28 AM
  2. Replies: 2
    Last Post: 08-03-2017, 04:58 AM
  3. Replies: 1
    Last Post: 10-27-2016, 12:14 PM
  4. Replies: 7
    Last Post: 08-26-2013, 06:05 AM
  5. Replies: 2
    Last Post: 08-30-2012, 07:59 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