The reason that you can't trap this error is that the script is not performed until after the validation error message pops up and since this validation error message does not trigger an error, this overwrites the error code with a 0.
Try using a script like this with the OnObjectValidate trigger:
Set Error Capture [on]
Commit Record [no dialog ] //trips the error, but with error capture on
If [Get ( LastError ) = 506 ]
Thanks Phil. That was my first guess (that the error disappears after the validation dialogue is delivered). I am using FMP Advanced 10 and I do not find a OnObjectValidate trigger. Is there another trigger event that would work?
OnObjectValidate is a newly added feature in FileMaker 11.
In that case, you'll need, unfortunately, to remove the field validation and script your own. Here's a test that is true only if the data entered is found in the list of values from the value list:
ValueCount ( FilterValues ( valueListItems ( Get ( FileName ) ; "valuelistnameInQuotesHere" ) ; YourTable::YourDropDownFieldHere ) )
You can put that expression inside a script performed by the OnObjectSave trigger and use Show Custom Dialog to pop up an error message that provides the user with an option to create a new record when the name entered is not found in the value list.
Phil - Thanks! Works perfectly. Now all I have to do is study the solution for a while to understand the approach.
Definitions and syntax for each of the functions used can be found in Filemaker help. If you read about them there and still have questions, feel free to post them here in the forum.