Results 1 to 2 of 2
  1. #1
    toqilula is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2011
    Posts
    5

    Unhappy Update, join, help

    Hi, Please find my code thats not working below
    Code:
    If DCount("Qty", "[closeTables]", "[Table] = " & Me.tableNameLbl.Caption & " and [Waiter] = '" & Me.usertxts.Caption & "'") = 0 Then
    DoCmd.RunSQL "INSERT INTO closeTables select * FROM orderTables where ([Table] = " & Me.tableNameLbl.Caption & " and [Waiter] = '" & Me.usertxts.Caption & "')"
    Else
    DoCmd.RunSQL "UPDATE orderTables LEFT JOIN closeTables ON orderTables.Item = closeTables.Item SET closeTables.Qty = [closeTables].[Qty] + [orderTables].[Qty] where ((orderTables.Item IN (Select Item  FROM closeTables WHERE ((orderTables.Waiter = '" & Me.usertxts.Caption & "') and (orderTables.Table = " & Me.tableNameLbl.Caption & ")) )) and (orderTables.Waiter = '" & Me.usertxts.Caption & "') and (orderTables.Table = " & Me.tableNameLbl.Caption & "))"
    DoCmd.RunSQL "INSERT INTO closeTables SELECT * FROM orderTables WHERE ((Item NOT IN (Select Item  FROM closeTables WHERE ((orderTables.Waiter = '" & Me.usertxts.Caption & "') and (orderTables.Table = " & Me.tableNameLbl.Caption & ")))) and ([Waiter] = '" & Me.usertxts.Caption & "') and ([Table] = " & Me.tableNameLbl.Caption & "))"
    i have two tables, and I want to update the quantity of an item from ordertables to closeTables meeting the criteria of having the same Waiter and Same Table. With this code when it updates, it updates all the quantitys of same Item, without criteria of Waiter or Table.
    So if i have :

    Code:
    orderTables                                                                                   closeTables
    
    

    ------------------------------- --------------------------------------- Item | Qty | Waiter | Table Item | Qty | Waiter | Table ------------------------------- --------------------------------------- Cola 1 As 1 Cola 1 As 1 Cola 1 As 2 ---------------------------------------------------------------------------
    and i do UPDATE i will have on closeTable
    Code:
    ------------------------------
    Item | Qty | Waiter | Table
    ------------------------------
    Cola       2        As         1  
    Cola       2        As          2    
    ------------------------------
    So notice the Qty is changed for both tabke 1 and table 2!!!
    I would need to change it only for Table1
    ---
    what am I doing Worng

    Thank you for your time.
    P.S. I hope I explained myself well

    Regards

  2. #2
    toqilula is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2011
    Posts
    5
    this worked
    Code:
    DoCmd.RunSQL "UPDATE closeTables RIGHT JOIN orderTables ON closeTables.Item = orderTables.Item SET closeTables.Qty = closeTables.Qty + orderTables.Qty WHERE closeTables.Qty Is Not Null and closeTables.Item = orderTables.Item and closeTables.Table = " & Me.tableNameLbl.Caption & " and closeTables.Waiter = '" & Me.usertxts.Caption & "'"
    DoCmd.RunSQL "INSERT INTO closeTables SELECT * FROM orderTables WHERE ((orderTables.Item NOT IN (Select Item  FROM closeTables WHERE closeTables.Item = orderTables.Item and closeTables.Table = " & Me.tableNameLbl.Caption & " and closeTables.Waiter = '" & Me.usertxts.Caption & "')))"
    thank you all

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

Similar Threads

  1. Replies: 3
    Last Post: 12-20-2010, 09:22 AM
  2. Access Update with Join Problem
    By saascuba in forum Access
    Replies: 3
    Last Post: 11-03-2010, 01:20 PM
  3. Update statement with linked table join
    By Guigui in forum Queries
    Replies: 6
    Last Post: 09-17-2010, 04:47 AM
  4. Replies: 3
    Last Post: 08-06-2009, 11:49 PM
  5. Update with LEFT JOIN
    By mcarthey in forum Access
    Replies: 1
    Last Post: 08-27-2008, 10:49 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