I am trying to make a small inventory program using Access but I don\'t have much knowledge, whatever I have done so far is by googling stuff. I Have managed to make code to
With parameters:
Dim db As Database
Dim qdf As QueryDef
Set db = CurrentDb
sSQL = "UPDATE Stock SET Stock_Qty = Stock_Qty + [p1] " & _
" WHERE Stock_PartNo = [p2] AND Stock_Location = [p3]"
''Temporary query
Set qdf = db.CreateQueryDef("", sSQL)
''No need to worry about quotes etc
qdf.Parameters("p2") = Me!Combo52
''Subtract
qdf.Parameters("p1") = Me.Text25 * -1
qdf.Parameters("p3") = Me.From
qdf.Execute dbFailOnError
''Add
qdf.Parameters("p1") = Me.Text25
qdf.Parameters("p3") = Me.To
qdf.Execute dbFailOnError
db.Execute "UPDATE Transaction SET Stock_Qty = Stock_Qty - " & Val(Me!Text25) _
& " WHERE Stock_PartNo = '" & Me!Combo52 _
& "' AND Stock_Location = '" & fromLocation & "'", dbFailOnError
db.Execute "UPDATE Transaction SET Stock_Qty = Stock_Qty + " & Val(Me!Text25) _
& " WHERE Stock_PartNo = '" & Me!Combo52 _
& "' AND Stock_Location = '" & toLocation & "'", dbFailOnError
Refer the link here for example code.