uniqueness of index is violated
-
Sunday, March 15, 2009 8:16 AMHi,
I have the following situation: I do have one table with a field, say 'names', where a CANDIDATE index is created on this field. I open a form and select names from a second table to populate the field in table one, but if for mistake the user select an previously selected name, the following error is presented:
"Error: loading file. Record number x. Loading form or the data environment: Uniqueness of Index JNAMES is violated."
I have been reading about using ON ERROR but I am confused,
How can I trap this error to avoid this situation? something like telling the user that the selected name in the second table is already selected or telling the user that the selected name will not be added to table one due to being already selected?
Thanks for any help
All Replies
-
Sunday, March 15, 2009 8:49 AMhello;
you can avoid this by make an interface contain textbox,verify command button and add button(make it disabled);when the user enter the name he'll click the verify button if the name exist a messagebox appear telling him that this name is already exist,if not the add button will be enabled.
use (locate for) instruction to search the name in table .
moradi -
Sunday, March 15, 2009 11:32 AM
To answer your question about ON ERROR specifically:
The first thing you need to do is to create an Error Handler - this can simply be a little program that accepts the parameters which are passed in when an error orccurs. Then you use the ON ERROR command in your startup program to tell VFP that when an error occurs it should call this program and pass in whatever parameters you specify (there are various options, but the basic ones are
- ERROR() - the error Number
- MESSAGE() - the Error Message
- PROGRAM() - the Name of the Program where the error occurred
So your set up command looks like this:
ON ERROR DO ErrHandler WITH ERROR(), MESSAGE(), PROGRAM()<BR>
And the ErrHandler Program like this:
LPARAMETERS
tnErrNum, tcErrMsg, tcProgram
IF tnErrNum = 1884 && Uniqueness of Index is violated
MessageBox( 'That Name is already in use, please choose another', 64, 'Duplicate Name' )
ENDIF
RETURN
Now when an error occurs, your code will be called and, if the error number matches the one specified, the message box will be displayed.
However, this is merely one way (and the simplest) to handle errors. For a more information check out the Fox Wiki on the subject, starting here:
http://fox.wikis.com/wc.dll?Wiki~DougHennigsErrorHandlingPaper~VFP
then follow the link for "CategoryErrorHandling"
-- Andy Kramek- Marked As Answer by Riquel_Dong Friday, March 20, 2009 1:15 AM
-
Monday, March 16, 2009 2:05 AMThanks for your replies!!!!!!
Problem solved with your suggestions. -
Tuesday, June 09, 2009 6:35 AMVery helpful, thank you Andy!!!!!

