DOCUMENT:Q164358 21-AUG-1999 [foxpro] TITLE :PRB: Handling Violation of Field Rules in Forms PRODUCT :Microsoft FoxPro PROD/VER:5.0 6.0 OPER/SYS: KEYWORDS:kbvfp kbvfp500 kbvfp600 ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual FoxPro for Windows, versions 5.0, 6.0 ------------------------------------------------------------------------------- SYMPTOMS ======== If the REVERT or HELP buttons are not desirable in the dialog box that Visual FoxPro 5.0 presents for violations of Field Rules, it is possible to trap the error and present a custom dialog box. These errors were not trappable in either Visual FoxPro 3.0 or 3.0b. RESOLUTION ========== There are basically three potential workarounds for this situation: The first can be with or without the use of classes. Using classes, however, is recommended and the implementation below allows you to use the workaround on a form not using any custom classes. 1. Create a custom Form Property called lFlagError. 2. In the Error Method of the Form, add the following code: IF nError = 1582 && Field "name" validation rule is violated THIS.lFlagError = .T. ENDIF 3. In the LOSTFOCUS of any TextBox that is based on a field with a field rule, add the following code: IF THISFORM.lFlagError NODEFAULT && Do not move Focus to Next Object THISFORM.lFlagError = .F. ENDIF The second option involves modifying the Field Rule. Instead of having a field rule that is merely an expression or a function that checks the condition and then returns a True or False, change the expression into a Function (or modify the existing function) so that it checks for the desired condition. In addition, if the rule fails, REPLACE the field with a valid value or the DEFAULT VALUE, as in the following example: Current Rule: .NOT. EMPTY() Modified Rule*: MyCustomRule() *Best placed in Store Procedures of the Database container FUNCTION MyCustomRule() IF EMPTY() REPLACE WITH ; EVAL(DBGETPROP('