PRB: REPLACE Causes "Field Rule Has Been Violated" ErrorID: Q129756 3.00 WINDOWS
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:
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:
MORE INFORMATION
Steps to Reproduce Behavior1. Create a new database container and modify it by issuing the following 2. Choose the New Table icon from the Database Designer toolbox, and add a
3. Add a validation rule to the stcode field that uses this expression:
4. Create a program that contains the following lines of code, and run it.
An error 1582 should occur.
Additional reference words: 3.00 VFoxWin KBCategory: kbprb KBSubcategory: FxprgMultiuser
|
Last Reviewed: May 22, 1998 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |