I have a quantity control in a form with the following code:
PublicOldQuantity As Long
Private Sub Quantity_GotFocus()
If IsNull(Quantity.Value) Then
OldQuantity = 0
Else
OldQuantity = Quantity.Value
End If
End Sub
Private Sub Quantity_AfterUpdate()
Dim ProductID As Long
Dim NewQuantity As Long
Dim db As DAO.Database
Dim strSQL As String
ProductID = Me.ProductID.Value
NewQuantity = Quantity.Value - OldQuantity
Set db = CurrentDb
strSQL = "UPDATE ProductT SET StockLVL = StockLVL - " & NewQuantity & " WHERE ID = " & ProductID
db.Execute strSQL
Set db = Nothing
Me.Requery
End Sub
I use pretty much the same Code in another form, just on a button and not in a after update event and it's working perfectly there. Here the query doesn't execute.
The same Query executed manually perfectly updates the StockLVL in the ProductT. Even writing the query as a separate Sub and calling that in the Event doesn't do anything. Also writing the query as a QueryDef Object with Parameters and calling that didn't work. I checked Parameters via Debug.Print and everything seems to be fine, the query just doesn't execute or at least the StockLVL Value in the ProductT doesn't update