What I usually do, is to make a business object that handles my data.
In this business object (in my case an invisible toolbar (because of its private datasession)) I implemented a locate function that locates a value for a given field.
If the location of the record fails, it means that the code is invalid, if it is sucesful it exists.
Since this is a genral handling method, I implemented it in a baseclass so that I can subclass it for every business object.
This is very handy to do, since this does not require any programming in the user interface, concerning data handling.
What I usually do is to validate the data on record level as well as on field level, especially with lookup fields.
If the value is incorrect, a popup will appear, if the user cancels, the value stays and the validated is validated again when the record is saved, and if the value is incorrect, the user should enter another.
Hope this will give yu some insight on the problem.
See my CrownBase app for the implementation for the things I just described.
Cheers,
Weedz (Wietze Veld)
My private project:
Download the CrownBase source code !!