Code:
Private Sub addprod()
Set db = CurrentDb
Set orderbasket = db.OpenRecordset("tblOrderBasket")
Set productDetails = db.OpenRecordset("SELECT * FROM tblProduct WHERE ProductID = " & Me.cmbProductID.Value)
If MsgBox("Would you like to order another item?", vbQuestion + vbYesNo, "Confirmation") = vbNo Then
Set order = db.OpenRecordset("tblOrder")
orderbasket.AddNew
orderbasket("OrderNo") = txtOrderNo.Value
orderbasket("ProductID") = cmbProductID.Value
orderbasket("Description") = txtDescription.Value
orderbasket("Category") = txtCategory.Value
orderbasket("Size") = txtSize.Value
orderbasket("Stock") = txtStock.Value
orderbasket("Quantity") = cmbQuantity.Value
orderbasket("Price") = txtPrice.Value
orderbasket("TotalPrice") = txtTotal.Value
'This finds the product currently being bought in the product table so the
'stock levels can be changed.
productDetails.Edit
cmbProductID = productDetails("ProductID")
'This changes the stock levels to minus the quantity being bought.
productDetails("Stock") = productDetails("Stock") - (Me.cmbQuantity.Value)
orderbasket("Stock") = productDetails("Stock")
'This updates the tables
orderbasket.Update
productDetails.Update
'This populates the list box to show all the products being ordered for the customer.
lstOrder.RowSource = ""
strsql = "SELECT tblOrderBasket.OrderBasketID, tblOrderBasket.ProductID, tblOrderBasket.[Description], tblOrderBasket.[Category], tblOrderBasket.[Size] ,tblOrderBasket.[Stock], tblOrderBasket.[Quantity],tblOrderBasket.[Price], tblOrderBasket.[TotalPrice]"
strsql = strsql & "FROM tblOrderBasket WHERE tblOrderBasket.[OrderNo] = " & Forms![frmOrder]![txtOrderNo] & ";"
Me![lstOrder].RowSource = strsql
'This ensures any item that is selected will not appear for the same order again
db.Execute "UPDATE tblProduct SET chosen = True WHERE ProductID = " & cmbProductID
lstOrder.Requery
cmbProductID.Requery
Thats my code