Article ID: 164358
Article Last Modified on 10/15/2003
IF nError = 1582 && Field "name" validation rule is violated
THIS.lFlagError = .T.
ENDIF
IF THISFORM.lFlagError
NODEFAULT && Do not move Focus to Next Object
THISFORM.lFlagError = .F.
ENDIF
Current Rule: .NOT. EMPTY(<fieldname>)
Modified Rule*: MyCustomRule()
*Best placed in Store Procedures of the Database container
FUNCTION MyCustomRule()
IF EMPTY(<fieldname>)
REPLACE <fieldname> WITH ;
EVAL(DBGETPROP('<alias.fieldname','FIELD','DEFAULTVALUE'))
ENDIF
The third option makes use of a Timer. The SETFOCUS of the object that
caused the Rule violation cannot be called from within the Form's ERROR
method due to the Visual FoxPro Object Model. At the time of the error the
current object is still the object that caused the error and its LOSTFOCUS
event has not yet occurred; therefore, when the ERROR method code is
finished, the object's LOSTFOCUS occurs, moving it to the next object in
the tab order, negating any SETFOCUS() command in the ERROR method of the
Form. The Timer allows the Object Model to progress through normally and
then move the focus back to the object that caused the rule violation. Use
the following steps to implement this workaround:
&& Turn the Timer back off
THIS.INTERVAL = 0
&& Tell the user there was an error
=MESSAGEBOX(MESSAGE(),48)
&& Put the user back in the control
THIS.oObjRef.SETFOCUS()
THIS.oObjRef=.NULL.
&& Check and see if the error was due to Rule Validation
IF nError = 1582
&& Store an object reference of the Current Control to the
&& custom property oObjRef
THIS.Errtimer1.oObjRef = THIS.ACTIVECONTROL
&& The interval can be critical, setting it to low and timing
&& problems occur, such as the Timer's custom property
&& not getting set.
THIS.Errtimer1.INTERVAL = 100
ENDIF
CREATE DATABASE beakrul
CREATE TABLE tTemp ;
(cFld1 c(3) CHECK .NOT. EMPTY(cFld1) ERROR 'Cannot be empty!')
CREATE FORM breakrul
APPEND BLANK
THISFORM.REFRESH()
158255 How To Modify a Rule's Table to Which It Belongs in VFP 5.0
Keywords: KB164358