Update code not working

K

Kevin

I have pasted my code. i am using the "update" and "where" commands. The
"were" parts is not working, the names are spelt correctly and they are both
text fields, it is not finding the names ,I am just not sure what i have done
wrong, any help would be great.

Me.tempqty = Me.Quantityinstock - Me.QTY
DoCmd.RunSQL "UPDATE [stock] SET [quantityinstock]=" & Me.tempqty & "
where [stocknumber]= " & Me.PartNo
Me.tempqty = 0
 
J

John W. Vinson

I have pasted my code. i am using the "update" and "where" commands. The
"were" parts is not working, the names are spelt correctly and they are both
text fields, it is not finding the names ,I am just not sure what i have done
wrong, any help would be great.

Me.tempqty = Me.Quantityinstock - Me.QTY
DoCmd.RunSQL "UPDATE [stock] SET [quantityinstock]=" & Me.tempqty & "
where [stocknumber]= " & Me.PartNo
Me.tempqty = 0

Open this code in the VBA editor and put a breakpoint on the DoCmd line (by
clicking in the vertical grey bar to the left of the code window). Run the
code; execution will stop at that line.

You can then type

?Me.PartNo

in the Immediate window to see what value Access is going to pass to the
query. Does the Stock table in fact have a record saved with that part number?
Is it the record currently open on the form (which may not yet be saved)?

John W. Vinson [MVP]
 
D

Damon Heron

Are tempqty and PartNo both numeric?

If so, then:

DoCmd.RunSQL "UPDATE stock SET quantityinstock = tempqty WHERE
((stock.stocknumber)=PartNo);"

Damon
 
Top