Results 1 to 5 of 5
  1. #1
    Oleksandr is offline Novice
    Windows 11 Access 2019
    Join Date
    Dec 2022
    Posts
    3

    Updating query a one table using another table with dates

    [COLOR=var(--black-200) !important][COLOR=var(--black-500) !important]0



    [/COLOR]
    [/COLOR]
    I have two tables, one with tasks and the other with some relative data as below:
    Task Client Date Hummer qty
    Made something a X1 01.02.2022
    Made something b X2 05.02.2022
    Made something c X3 05.02.2022
    Made something d X2 07.02.2022

    So this one represents daily activity for different clients. I need to fill "Hummer qty" column for every day entered for every Client using second table below where there is Dated history of each Client, at which dates quantity of hummers were increased by each Client.
    Client Date Hummer qty
    X1 15.03.2021 1
    X1 23.05.2021 3
    X2 08.02.2019 1
    X2 06.02.2022 2
    X2 06.03.2022 3
    X3 16.03.2022 1

    as a result, first table should be as below:
    Task Client Date Hummer qty
    Made something a X1 01.02.2022 3
    Made something b X2 05.02.2022 1
    Made something c X3 05.02.2022 0
    Made something d X2 07.02.2022 2

    in this case tried to use Dlookup with conditions where daily dates >= to history dates + Clients are identical between tables. But it does not work (empty). Simple query returns only first found quantities in history and set it to all the rows of respective client.



  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    You may want to look at this example Browne from Allen Browne for using subqueries to get the data from another record;
    http://allenbrowne.com/subquery-01.html

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,144
    You shouldn't store that qty as a field value in the first table, you should always calculate it in a query and then display that when you need it.
    If you store it you can't be certain that it's accurate unless you update it every time the second table is altered. This is poor practice and design, and causes you extra work.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    Oleksandr is offline Novice
    Windows 11 Access 2019
    Join Date
    Dec 2022
    Posts
    3
    thank you for these advices!

  5. #5
    Oleksandr is offline Novice
    Windows 11 Access 2019
    Join Date
    Dec 2022
    Posts
    3
    Tried to make it but again it finds first value under condition (for example 3) and sets it for all the rows even for those where value 4 should be.

    UPDATE tasksImport INNER JOIN acCount ON tasksImport.Client = acCount.Client SET tasksImport.acGrow = [acCount]![acGrow]
    WHERE (((Exists (SELECT tasksImport.DateStartDate
    FROM tasksImport INNER JOIN acCount ON tasksImport.Client = acCount.Client
    WHERE (((tasksImport.DateStartDate)>=[acCount]![DateFrom]));
    ))=True));

    taksImport is Table1 from my request above, acCount is Tbale2 and acGrow are hummers values. Maybe you could review it and advise, please... Thank you!

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

Similar Threads

  1. Replies: 11
    Last Post: 02-09-2019, 06:36 AM
  2. Replies: 2
    Last Post: 11-11-2016, 09:07 AM
  3. Replies: 5
    Last Post: 07-12-2014, 02:55 PM
  4. Replies: 6
    Last Post: 05-10-2012, 08:20 PM
  5. Updating a Table from a second Query.
    By israellawndale in forum Access
    Replies: 4
    Last Post: 09-22-2011, 02:51 PM

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