I need to deduct a quantity from a table by matching the ID of the product. If I run the below code, it deducts a quantity but the problem is for instance...
I enter ID number as 1 and have to click deduct button twice to deduct.
Second time I change ID number to 2 and click deduct button... First time it deducts from ID number 1 itself. But now if I click once more, it deducts from ID number 2.
How can I solve this problem?
I'm using MS Access as database (ADODB).
Option Explicit
Dim con As New ADODB.Connection
Dim rst As ADODB.Recordset
Dim sql As String
Private Sub Command1_Click()
Set con = New ADODB.Connection
Set rst = New ADODB.Recordset
con.Open (adodc1.ConnectionString)
sql = "UPDATE stock SET QTY = QTY - 1 WHERE ID = '" & IDval.Text & "'"
con.Execute (sql)
Adodc1.Recordset.Update
Adodc1.Refresh
con.Close
End Sub
Thank you in advance.