PRB: REPLACE Causes "Field Rule Has Been Violated" ErrorLast reviewed: April 30, 1996Article ID: Q129756 |
The information in this article applies to:
SYMPTOMSIf you programatically or interactively replace a field with an illegal value, you may receive an error number 1582:
Field <fieldname> Rule has Been Violated. CAUSEThe value that you attempted to place in the field caused a value of .F. to be returned from the validation rule defined in the database container for this field. If you replaced the field with an invalid value programatically, Visual FoxPro returns error number 1582 and executes an ON ERROR routine if one is in effect. If you replaced the field interactively, no error number is returned, and the ON ERROR routine is not executed. You will be unable to move the pointer (cursor) off the offending field until an acceptable value is typed in.
RESOLUTIONYour ON ERROR routine must handle error 1582. Although it may seem logical to have your ON ERROR routine issue a REPLACE statement to replace the field with the OLDVAL(<fieldname>) function, you should simply return .F. from your ON ERROR routine. When you return .F., Visual FoxPro takes care of returning the field's value to its value before the change. By returning .F., you enable your ON ERROR routine to handle both existing and newly appended records. The OLDVAL() function always returns blank for an appended record, even if the database container specifies a default value for the field. The code snippet below demonstrates how to handle error 1582 in an ON ERROR routine:
ON ERROR DO errhandler PROCEDURE errhandler = AERROR(aLastErr) DO CASE CASE aLastErr(1) = 1582 RETURN .F. * Include code to handle other anticipated errors. ENDCASE MORE INFORMATION
Steps to Reproduce Behavior
|
Additional reference words: 3.00 VFoxWin
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |