The z value has not been set when the debugger is on the z = rst.Fields("Qty") - txtqty.Text. The line must be executed first. Check the z value when debugger reaches the rst!Qty rst!Qty = z line.