
Originally Posted by
June7
The code is not in the "Update Stock" button click event. It is is in an event with a name of a button that doesn't exist. Form in design view, select the Update Stock button, double click the OnClick event property ellipses, type code in the event.
Also this is a form/subform. The button is on main form and Quantity and PartID are on subform. So reference to Quantity and PartID is trickier. Give the subform container control a name different from the form it holds, like ctrJobParts. Then:
CurrentDb.Execute "UPDATE tblPart SET QuantityInStock = QuantityInStock - " & Me.ctrJobParts.Form.Text11 & " WHERE PartID='" & Me.ctrJobParts.Form.Combo4 & "'"
or
CurrentDb.Execute "UPDATE tblPart SET QuantityInStock = QuantityInStock - " & Me.ctrJobParts!Quantity & " WHERE PartID='" & Me.ctrJobParts!PartID & "'"
PartID is text so apostrophe delimiters are needed.
So here's what I'm doing:
- frmJobPart Design View
- Selecting button "Update Stock"
- Opening the "Code Builder" using the ellipses in the "On Click" field of the button's Property Sheet
- Typing in the code so I have:
Private Sub Update_Stock_Click()
CurrentDb.Execute "UPDATE tblPart SET QuantityInStock = QuantityInStock - " & Me.ctrJobParts.Form.Text11 & " WHERE PartID='" & Me.ctrJobParts.Form.Combo4 & "'"
End Sub
But when I try to run the code via the button I just get an error message saying "Compile Error: Invalid outside procedure". I don't know what I'm doing wrong. 
Thanks for all your help so far, you've been great.