Validating multiple fields prior to database record insertion/update
Posted on 2008-10-27
I've got 3 fields on a form, start time, end time and duration; pretty simple and I'm trying to validate them. Start time and end time are optional if duration is provided. Likewise if start and end times are provided, duration will be calculated automatically if not provided. If all 3 are present, duration must be the difference between the start and end times. Finally, start time without end time is prohibited and visa-versa.
I was attempting to validate this in the Before_Update event but since I have all the validation code present, checking all the conditions, when entering a new db record, I'm getting lots of error messages informing me of conditions I know aren't correct because I haven't entered the data yet. What I seem to need is an event that gets fired just before the record is to be written so I can validate all fields together not each individually since there is a dependency. How can this validation be done without the use of an Update/Insert button type of logic?