********************************************************************** FUNCTION RecordValid(tcTableName, llEvaluateAllRules) * Record validation. * Meant to be invoked from form.valid((tablename)). * Can also be invoked from other places, for instance, triggers. tcTableName = lower(tcTableName) llEvaluateAllRules = .T. && Currently, I override second parameter. * save and change settings local lnOldAlias, lcOldExact lnOldAlias = select() lcOldExact = set("exact") set exact off * open validation table if used("validation") select validation else select 0 use validation again endif set order to "mainorder" * evaluate all errors defined in rules table local lcErrorText, llError lcErrorText = "" tcTableName = padr(tcTableName, len(Table)) seek tcTableName scan while table = tcTableName select (lnOldAlias) if not evaluate(validation.rule) lcErrorText = lcErrorText + iif(validation.warning, "Warning: ", "Error: ") + validation.spanish if not validation.warning llError = .T. endif if llEvaluateAllRules lcErrorText = lcErrorText + chr(13) else exit endif endif select validation endscan * show error message if not empty(lcErrorText) * wait window nowait "Can't save changes:" + chr(13) + chr(13) + lcErrorText MessageBox(iif(llError, "Can't save:", "Warning on save:") + chr(13) + chr(13); + lcErrorText + iif(llError, "", chr(13) + "Changes saved."),; 16, iif(llError, "Error saving", "Warning on save")) endif * restore environment and return success status use in validation select (lnOldAlias) set exact &lcOldExact return not llError ENDFUNCWith this validation I intercept most error conditions from Visual FoxPro, including (with specially designed functions) "trigger failed" when the user tries to save a record in a child table before saving the record in the parent table, and duplicate records.