Microsoft KB Archive/138559

= How to Append Records to a Grid =

Article ID: 138559

Article Last Modified on 11/17/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft Visual FoxPro 3.0b for Macintosh

-



This article was previously published under Q138559



SUMMARY
There are times when a user may want to append a record when they get to the last record in a grid. This can be accomplished programmatically by using the BeforeRowColChange and the AfterRowColChange events as shown by example in this article.



MORE INFORMATION
One important piece of the example is setting the buffer mode of the form to either optimistic or pessimistic. This allows the GETFLDSTATE function to perform correctly. In addition, this sample code uses no index order on the data.

Step-by-Step Example
 Open the Forms Designer, and drop a grid on it. Create a new property of the form called nLastRec.  In the Init event of the grid, place this code: GO BOTTOM ThisForm.nLastRec = RECNO GO TOP   Place the following code in the BeforeRowColChange event. LPARAMETERS nColIndex  && This line is added automatically by FoxPro && nColIndex is current column the cursor is in  IF nColIndex = This.ColumnCount AND RECNO = ThisForm.nLastRec ; AND LASTKEY = 9 APPEND BLANK ThisForm.nLastRec = RECNO This.SetFocus ENDIF This code appends a record only if you press the TAB key to move through the fields. Code would have to be added for conditionally appending records based on different navigation through the fields.   Place the following code in the AfterRowColChange event: IF "3"$GETFLDSTATE(-1) This.ActivateCell(This.ActiveRow, nColIndex) ENDIF   Add code similar to the following to commit the changes to the table. This code can go into the Click event of a command button or in the Destroy event of the form. IF      =TableUpdate(.T.) ELSE =TableRevert(.T.) ENDIF </ol>

Additional query words: VFoxMac VFoxWin

Keywords: kbcode KB138559

-

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

© Microsoft Corporation. All rights reserved.