I have a form with a combo box which is linked to a table (TblProduct)which show the product description and is ordered by the product ID
I also have a text box called txtStockValue.
I want users to select the product form the combo box, do a stock count and input the stock value in the txtStockValue box.
There is then a button which confirms the update.
I have the following coding for the button, but I put the problem in this section of the forum because I think my problem is in the query… I have never used combo boxes before
the coding is as follows
Private Sub StockOK_Click()
Dim SQLDelete1 As String
Dim SQLDelete2 As String
Dim SQLUpdate As String
SQLDelete1 = "DELETE * FROM TblStock WHERE TblStock.ProductID = CboStockItem.ProductID"
SQLDelete2 = "DELETE * FROM TblTotalSales WHERE TblTotalSales.ProductID = CboStockItem.ProductID"
SQLUpdate = "INSERT INTO TblStock (ProductID, StockLevel) SELECT ProductID FROM CboStockItem.ProductID AND SELECT StockLevel FROM TxtStockValue"
If IsNull(Me.TxtStockValue) Then MsgBox "Please Select An Item To Update Stock And Ensure A Value Has Been Entered" Else:
DoCmd.RunSQL SQLDelete1
DoCmd.RunSQL SQLDelete2
DoCmd.RunSQL SQLUpdate
End Sub
I tried to reference the combo box as CboStockItem (The name of the combo box) but I don’t think I have done this correctly.
The code is basically supposed to delete all the items form 2 tables where the items ID is the same as in the product selected from the combo box and then insert the new value for stock into the stock table.
A secondary point is that before the data is deleted it should be updated into two excel files for storage (a stock Excel file called Stock and a sales Excel file called sales). This I think I can do, but I thought to include it for interest.
Your string to set your SQL should be like this: