How To Check for Changed Record in Grid & Prompt User to Save

Last reviewed: March 12, 1998
Article ID: Q149383
3.00 3.00b 5.00 WINDOWS kbprg kbhowto kbcode

The information in this article applies to:

  • Microsoft Visual FoxPro for Windows, versions 3.0, 3.0b, 5.0

SUMMARY

This article shows by example how to:

  • How to check to see if a record has been changed when you're using a grid to edit records in a table with Table Buffering.
  • How to prompt users to update a changed record before they move to a different record.

MORE INFORMATION

If you are not familiar with Data Buffering, please see Chapter 19 in the Developer's Guide. For more information on using Forms and Controls, please see Chapters 9 and 11 in the Developer's Guide.

Step-by-Step Example

  1. Create a new form. Add the Customer table (located in Samples\Data in the Visual FoxPro directory) to the form's Data Environment

  2. Set the BufferMode property of the form to one of the values below:

          1 - Pessimistic
    

            -or-
    
          2 - Optimistic
    
       With either of these settings, the grid, soon to be added to the form,
       uses table buffering while any other controls, such as text boxes or
       edit boxes, uses row buffering. Alternately, the BufferModeOverride
       property of the cursor can be set to either of these values:
    
          4 - Pessimistic Table Buffering
    
            -or-
    
          5 - Optimistic Table Buffering
    
       The BufferMode property of the form can be set as desired. The code in
       this article will not work if the BufferModeOverride property of the
       cursor is set to either type of Row Buffering. This is because with Row
       Buffering on the cursor in the grid, any changes to the current record
       will be committed when moving to the next record in the grid and the
       GETFLDSTATE() function will not detect the change.
    
    

  3. Add two new properties to the form, and call them nRecNum and nWhatRow. Set their Value properties to 0.

  4. Add a grid to the form, and set the following properties for the grid:

    RecordSource = Customer RecordSourceType = 1 - Alias

  5. Add the following code to the indicated grid events:

    Init event

           ThisForm.nRecNum = RECNO()
    

    BeforeRowColChange

           ThisForm.nRecNum = RECNO()
    

    AfterRowColChange

           lMov = .F.
           IF ThisForm.nWhatRow # This.ActiveRow
    
                ThisForm.nWhatRow = This.ActiveRow
                nHold= RECNO()
                GO ThisForm.nRecNum
                cChange = GetFldState(-1,'Customer')
                IF AT('2', cChange)>0
                  This.Refresh
                  lMov = .T.
                  IF MessageBox("Update Record",4)= 6
                    =TableUpdate(.T.)
                  ELSE
                    =TableRevert(.T.)
                  ENDIF
                 ENDIF
                 GO nHold
                 IF lMov
                   This.Refresh
                   lMov =.F.
                 ENDIF
               ENDIF
    
    

  6. Save and run the form.

Users are prompted to save the record when they change a value in the record and move to a different row in the grid. A Yes response fires a TableUpdate event, and a No response fires a TableRevert event.


Additional reference words: 5.00 3.00 3.00b VFoxWin
KBCategory: kbprg kbhowto kbcode
KBSubcategory: FxprgGrid

Keywords : FxprgGrid kbcode kbhowto kbprg
Version : 3.00 3.00b 5.00
Platform : WINDOWS


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: March 12, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.