","qryCodes","[Code] = '" & txtCode & "'") Then
MsgBox "That is not a valid code."
Cancel = True
End If
"Cancel = True" cancels the update event so the bad data cannot be saved.
The easiest and most user friendly answer is to use a combobox with its limit to list property set to yes.