Microsoft KB Archive/158255

= How To Modify a Table in Visual FoxPro Using Its Rules =

Article ID: 158255

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q158255



SUMMARY
In Visual FoxPro 5.0 or later, the field validation rules and the record validation rules can now modify the table to which they belong. This is not possible in Visual FoxPro 3.0.



MORE INFORMATION
For example, suppose you want to track when each update was made to a record, check a maximum order amount, and capitalize entries in a certain field. The following steps illustrate how this might be done.

 Create a new DBC called "mydbc."  Issue the following command to create a table: CREATE TABLE cust(custname c(10),chg_date D, order N(5), ;     max N(5), limit L)                         Enter some records in the table.  Enter the following in the stored procedures: PROCEDURE rec_valid REPLACE chg_date WITH DATE IF order > max REPLACE limit With .t.        ELSE REPLACE limit with .f.        ENDIF ENDPROC

PROCEDURE fld_valid IF !EMPTY(ALLTRIM(custname)) AND ; ALLTRIM(PROPER(custname))<>ALLTRIM(custname) REPLACE custname WITH PROPER(custname) ENDIF ENDPROC  Modify the table, and in the record validation rule type rec_valid. In the field validation rule for custname, type fld_valid. Browse the table, add new records, and edit existing records.</li></ol>

Notice the chg_date is modified for each new record and for any existing record that is edited. The limit field is set to true each time the order field exceeds the max field. The first letter of custname is always capitalized regardless of how the name is entered or changed.

Keywords: kbhowto kbdatabase KB158255

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.