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