• updtate and delete a query

    Author
    Topic
    #354125

    I have a main form containing the CustomerID and a subform containing the different orders by customers.
    The subform is based only on the table Orders and has the following RecordSource:
    SELECT orders.orderid, orders.customerid FROM orders;

    Each order contains different products and therefore each order has several records.I want to delete all the records
    from a given order and update them.To this end i must build a query based on three tables: orders, orderdetails and produccts.
    and build a query of the sort of:
    SELECT orders.orderid, products.Productid, products.stock, [order details].cartons
    FROM orders INNER JOIN (products INNER JOIN [order details] ON (products.Productid = [order details].ProductID) AND (products.Productid = [order details].ProductID)) ON orders.orderid = [order details].OrderID;
    After building the query, i wanrt to click the order that is clicked on above subform, where only the OrderId is shown, and give a command to update and delete all the records within the order being clicked.

    CurrentDb.Execute “UPDATE Products INNER JOIN [Order Details] ON Products.ProductID = [Order Details].ProductID SET Products.stock = [Products].[stock]+[Order Details].[Cartons], WHERE ((([Order Details].OrderID)=” & txtOrderID & “));”
    CurrentDb.Execute “DELETE * FROM [Order Details] WHERE orderid = ” & txtOrderID & “;”

    However nothing works.

    I know that in theory it is possible but all my effors were in vain.

    I will be very much obliged to any help.Just to mention that my
    database folows very closley the database Nothwind traders shipped with Microsoft.

    Viewing 1 reply thread
    Author
    Replies
    • #519747

      I’m a little confused (I’m a lot confused).

      You want to UpDate and then Delete the records of your subForm? Why not just Delete the Records? And have done with it.

      Or do you want to change the records of your subForm, and make corrections to those records.

    • #519778

      what are you updating in the records
      and why do you need to delete before updating
      JerryC

    Viewing 1 reply thread
    Reply To: updtate and delete a query

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: