How to Check for Changes Made in a Database Record

Last reviewed: April 29, 1996
Article ID: Q97638
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a

SUMMARY

The UPDATED() function returns .T. if any GET field was changed during a READ command. Since push buttons, radio buttons, lists, invisible buttons, and spinners (spin boxes) are considered GET fields, UPDATED() will also return .T. if any of these controls are accessed during a READ command.

MORE INFORMATION

To write a simple code snippet to verify if any data in the current record was changed during a READ command, do the following:

  1. When the record pointer is moved to a record, scatter the data to an array by issuing the following command:

          SCATTER TO beg_edit MEMO    && MEMO is required only if memo
                                       && fields are being verified.
    
       If the record pointer is pointing to the same record in more than one
       session, move the record pointer off the record and then back in order
       to get current information:
    
          SKIP     && provided we are not at EOF()
          SKIP -1  && to return to the same record
                   && Now the second SCATTER will work correctly.
    
    

  2. After all changes are complete, issue the following commands. Normally this code snippet would appear in the VALID clause of a push button or other control labeled to save the changes.

          * Scatter to a second array for comparison.
          SCATTER TO end_edit MEMO
    

          * Check each element in the array against the original data.
          FOR i = 1 TO alen(beg_edit)
    
            IF beg_edit(i) <> end_edit(i)
                * Return .F. if any element has changed.
                RETURN .F.
            ENDIF
          ENDFOR
          RETURN .T.
    
    
To check for changes during a BROWSE, execute the code in step 1 in a BROWSE WHEN user-defined function (UDF). Execute the code in step 2 in a BROWSE VALID UDF.

Notes

  • A set of two arrays is used for simplicity and portability. By using two arrays, the same code will work with any database, regardless of field names, field types, or number of fields.
  • Caution must be used when scattering large memo fields. If there is insufficient memory to hold the entire contents of the memo field, the memo field will not be scattered.
  • SET EXACT should be set to ON in order to eliminate the possibility of strings of different length comparing as equal.

For more information, see the version 2.0 "Commands & Functions" manual or the version 2.5 "Language Reference" manual.


Additional reference words: FoxDos FoxWin 2.00 2.50 2.50a test testing tell
determine information data field compare comparison check "field change"
KBCategory: kbprg
KBSubcategory: FxprgBrowse


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 29, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.