NewVFP


Hi Everybody,

Help me, please

I have problem with unique index.

How to catch the message "The uniqueness of primary or candidate key is violated." (Error 1884) in Browse window (or Grid control). Because I want to display my message instead VFP's meassage.

I use VFP9.

Sorry because my english is not good!

Thanks everybody




Re: Catch "The uniqueness of primary or candidate key is violated." (Error 1884) in Browse window

Markish


Hi,
For trapping the error 1884, You can add code to the 'error' event of the grid.

Code Block

LPARAMETERS nError, cMethod, nLine

DO case

CASE nerror=1884

MESSAGEBOX("Primary Key Duplicated...")

&& Handle the duplication

OTHERWISE

ENDCASE

For trapping in the Broswe window, I'm not sure if it can be done.

Hope this helps...

Best regards,

Markish







Re: Catch "The uniqueness of primary or candidate key is violated." (Error 1884) in Browse window

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.






Re: Catch "The uniqueness of primary or candidate key is violated." (Error 1884) in Browse window

NewVFP

Hi all (Markish,CetinBasoz),

Thanks in advance for your helps.

I solved my prolem.

I'm sorry, because my english is not enough to say thank to you.

Best regards,

Minh Tran