In order to prevent the original action (exit), you need to exit the script with a result of 0, or false.
Use the OnObjectValidate script trigger, and make sure you add an Exit Script script step with a script result of False (or 0, which is equivalent), which will abort the operation that triggered the script, i.e. will not allow you to leave the field. Exit Script [True] (or 1) will signal FM that the validation succeeded, and that the event may proceed.
Chris.. If this is attched to the OnObjectExit trigger for the code field wont clicking on the Dialog button be prevented?
Got this working now for both fields I need it on.
what dialog button?