Microsoft KB Archive/137682

= PRB: "Record validation rule is violated" Error in a Form =

Article ID: 137682

Article Last Modified on 8/3/2000

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition

-



This article was previously published under Q137682



SYMPTOMS
Moving off a record that has row-level validation and invalid entries causes the form to produce this error message:

Record validation rule is violated



CAUSE
Issuing a SKIP or SKIP-1 while positioned on a record that has invalid entries fires an implicit TABLEUPDATE function call, which tries to write your invalid data to the table.



RESOLUTION
Incorporate buffering in the form, and control the use of the TABLEUPDATE function and navigation buttons. For example, remove the asterisk from the code in steps 7 and 12 in the "Steps to Reproduce Behavior" section of this article to resolve the problem.



STATUS
This behavior is by design.



MORE INFORMATION
Use the following steps to create a form that appends a record to a table using a row-level validation rule entered in the Table Designer.

Steps to Reproduce Behavior
  On the File menu, click New. Then select the Table check box, and click New File. Create a new Table called Table1 that has this structure:   Field Name   Type       Width -  FLD1         Character  10 FLD2        Character  10  On the File menu, click New. Select the Database check box, and click New File. Create a new Database called Data1. Right-click inside the gray DataBase Designer window. Click Add Table, and select Table1. Right-click Table1, which was just added to the database, and click Modify. Click the Table Properties button located in the top-right corner of the Table Designer dialog box. In the Validation Rule field, type ! EMPTY(fld1). In the Validation Text field, type FLD1 must have a value.  Click OK, and then click OK in the Table Designer dialog box. Click Yes to make structure changes permanent. Double-click the top-left corner of the DataBase Designer window to close it. On the File menu, click New, select the Form check box, and then click New File. Right-click the form, and then click Data Environment. Right-click the gray Data Environment window, click Add. Then in the Add Table or View dialog box, click Other, and then select Table1.dbf.</li> When the table has been added to the data environment, drag both fields from the data environment onto the form. Double-click the top-left corner of the gray Data Environment window to close it.</li>  Double-click the form, and place the following code in the form's Activate event: APPEND BLANK * THISFORM.Command1.Enabled=.F.  * THISFORM.Command2.Enabled=.F.   * THISFORM.Command3.Enabled=.F.   OPEN DATABASE data1.dbc EXCLUSIVE </li>  Place the following code in the form's Load event: SET MULTILOCKS ON  =CURSORSETPROP("Buffering",2) </li>  Place first of four command buttons (Command1) on the form. Set its Caption property to Next, and place the following code in its Click event: SKIP THISFORM.Refresh </li>  Place another command button (Command2) on the form. Set its Caption property to Previous, and place the following code in its Click event: SKIP -1 THISFORM.Refresh </li>  Place a third command button (Command3) on the form. Set its Caption property to Quit, and place the following code in its Click event: RELEASE THISFORM </li>  Place a fourth command button (Command4) on the form. Set its Caption property to Write, and place the following code in its Click event: lsuccess=TABLEUPDATE(.T.) IF ! lsuccess =AERROR(aErrors) DO CASE CASE aErrors[1,1] = 1583 SELECT table1 cRuleText=dbgetprop("table1","TABLE","RuleText") =MESSAGEBOX(cRuleText,48) ENDCASE ELSE *  THISFORM.Command1.Enabled=.T.       *   THISFORM.Command2.Enabled=.T.       *   THISFORM.Command3.Enabled=.T.    ENDIF </li> Run the form, and click the Previous button.</li></ol>

<div class="references_section">