CetinBasoz
There are several solutions to the problem. One is using an error handler as Markish showed (works with browse too - check 'on error' for samples).
My preference is not to let the error occur in the first place (for primary keys). For PK IMHO it should be a generated id and not something user can create/change himself (surrogate key). Check nextid example in solution app and autoinc fields for integer type PKs. I prefer to use GUIDs which do not need any special checking.
For candidates however you should check and prevent the message. Using buffering helps in that case. You check the value before it's checked and attempted to be updated by VFP. For example using indexseek().
There are other ways too but these are easier basic ones.