Results 1 to 6 of 6
  1. #1
    anthgav is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    86

    Update query based on 2 criteria with the same join


    Hi

    I am trying to create an update query, the query is called qryUpdateZeroLocations here is what I have so far...

    Code:
    UPDATE tblBinType RIGHT JOIN (tblBin LEFT JOIN (tblAllocatedBin LEFT JOIN tblProduct
    ON tblAllocatedBin.allocated_bin_id = tblProduct.allocated_bin_1)
    ON tblBin.bin_id = tblAllocatedBin.allocated_bin) ON tblBinType.bin_type_id = tblAllocatedBin.allocated_bin_type
    SET tblBin.bin_width_mm = 0
    WHERE (((tblProduct.allocated_bin_1) Is Null) AND ((tblBinType.calculate_bin_by_product)=True));
    This query needs to set 'tblBin.bin_width_mm' field to 0 based on the conditions in the query. The query checks to see if the bin is being used in the 'tblProduct.allocated_bin_1' and if tblBinType.calculate_bin_by_product' is set to true.
    So far this works but what I want is for the query to check if 'tblProduct.allocated_bin_1' and 'tblProduct.allocated_bin_2' is using a location. I'm struggling to make the query check both of these fields as they require the same join to 'tblAllocatedBin' table.

    Please can you help?

    Here is an attached sample, ignore the error that pops up upon opening as I stripped the file down.
    Update Bins to Zero.zip

    Thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Can't look at the sample right now, but it sounds like you need to add a second instance of tblAllocatedBin to the query and join the second field to it. Access will alias it to ..._1.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    anthgav is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    86
    Quote Originally Posted by pbaldy View Post
    Can't look at the sample right now, but it sounds like you need to add a second instance of tblAllocatedBin to the query and join the second field to it. Access will alias it to ..._1.
    Thanks, what you said pointed me in the right direction. I seem to have got it to work by adding 2 instances of tblProduct and joining them to tblAllocatedBin.

    Code:
    UPDATE (tblBinType RIGHT JOIN (tblBin LEFT JOIN (tblAllocatedBin LEFT JOIN tblProduct
    ON tblAllocatedBin.allocated_bin_id = tblProduct.allocated_bin_1)
    ON tblBin.bin_id = tblAllocatedBin.allocated_bin)
    ON tblBinType.bin_type_id = tblAllocatedBin.allocated_bin_type)
    LEFT JOIN tblProduct AS tblProduct_1
    ON tblAllocatedBin.allocated_bin_id = tblProduct_1.allocated_bin_2
    SET tblBin.bin_width_mm = 0
    WHERE (((tblProduct.allocated_bin_1) Is Null) AND ((tblProduct_1.allocated_bin_2) Is Null) AND ((tblBinType.calculate_bin_by_product)=True));

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Sorry about mentioning the wrong table; that's what I get for posting right after I wake up.

    Glad you figured it out.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    anthgav is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    86
    No problem. Windows XP?, Time for you to upgrade I think.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    No, time to change my profile!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 10-18-2016, 08:31 PM
  2. Replies: 5
    Last Post: 09-05-2016, 09:07 AM
  3. update query with inner join roundup
    By tmcrouse in forum Access
    Replies: 2
    Last Post: 04-01-2015, 12:09 PM
  4. Update in Simple Join Query
    By drunkenneo in forum Queries
    Replies: 3
    Last Post: 11-21-2013, 11:35 AM
  5. Replies: 1
    Last Post: 10-29-2012, 08:15 AM

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