Microsoft KB Archive/141740

= PRB: APPEND BLANK on a Child Grid Does Not Display New Record =

Article ID: 141740

Article Last Modified on 11/17/2003

-

APPLIES TO


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

-



This article was previously published under Q141740



SYMPTOMS
In a one-to-many form, when you want your form to have the ability to add child records into the grid, you find that clicking the grid does not allow you to scroll beyond the last record. Adding a button that uses APPEND BLANK to add a new child record won't add a record to the grid.



CAUSE
In a one-to-many form the grid only displays related records -- records that have a key identical to the key of the parent. When you issue an APPEND BLANK command, the key field in the new record is blank and is therefore not displayed in the grid.



RESOLUTION
After issuing an APPEND BLANK command, use REPLACE to write a value to the key field. You can also use the INSERT command with the VALUES clause instead of APPEND BLANK. For example, remove the asterisk from the code in step 4 below, or use the command button in Step 5 to resolve the problem.



STATUS
This behavior is by design.



MORE INFORMATION
Use the following steps to create a one-to-many form with a command button that calls APPEND BLANK and a command button that calls INSERT.

Steps to Reproduce Behavior
 Create a new form. In the Data Environment of the form add \Vfp\Samples\Data\Orders.dbf. Then add the table \Vfp\Samples\Data\Orditems.dbf Drag some fields from the Orders table in the data environment onto the form. Click the title bar of the Orditems table in the data environment, and drag it onto the form to create a grid.  Add a command button to the form, and set its Caption property to Append. Add the following code to the Click event of the button: SELECT Orditems APPEND BLANK * REPLACE order_id WITH Orders.order_id SELECT Orders THISFORM.Refresh   Add another command button to the form, and set its Caption property to Insert. Add the following code to the Click event of the button INSERT INTO orditems (order_id) VALUES (Orders.order_id) THISFORM.Refresh </li>  Add a final command button to the form, and set its Caption property to Exit. Add the following code to the Click event of the button: RELEASE THISFORM </li> Click the View Classes button on the form control toolbar. Select Add from the menu. In Visual FoxPro 5.0, double-click the file in \Vfp\Samples\Classes\Buttons.vcx. Or in Visual FoxPro 3.0, double-click the file in \Vfp\Samples\Controls\Buttons.vcx. Select the VCR control, and drop it onto the form.</li> Run the form, and click the Append button.</li></ol>

<div class="references_section">