Microsoft KB Archive/148332

= BUG: GRID: SET RELATION TO Does Not Break Relation Properly =

Article ID: 148332

Article Last Modified on 5/7/2003

-

APPLIES TO


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

-



This article was previously published under Q148332



SYMPTOMS
When you use the SET RELATION TO command to break an existing relationship, the only records displayed from the relationship's child table are those that are related to the current parent record and beyond. Any child records that match parent records prior to the current parent record are left out.



Method One
After using the SET RELATION TO command to break the relation, use the SELECT command to select the child table, and then use the USE command. This closes the child table.

Open the table again by using the USE command. Set the RecordSource property of the grid back to the child alias. The code to do this would look similar to this code: SELECT orders             && Select the child table USE                       && Close the child table USE orders ORDER cust_id  && Open the child table and reset the order ThisForm.Grid1.RecordSource = "Orders"   && Reset RecordSource ThisForm.Refresh          && Refresh the form

Method Two
Use the following code to break the relation. This will allow you to see all the child records in the grid without resetting any of the grid properties. ThisForm.LockScreen = .T. && Lock the form SELECT orders             && Select the child table nChildRec = RECNO       && Store the current child record number SELECT customer           && Select the parent table nParentRec = RECNO      && Store the current parent record number GO TOP                    && Go to the top record in the parent table Thisform.Refresh SET RELATION TO           && Break the relation ThisForm.Grid1.RecordSource = ThisForm.Grid1.RecordSource * Force the grid to look at the child table again SELECT orders             && Select the child table GO nChildRec              && Go to the child record we were on   SELECT customer            && Select the parent table Go nParentRec             && Go to the parent record we were on   Thisform.Refresh ThisForm.LockScreen = .F. && Unlock the form



STATUS
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.



Steps to Reproduce Problem
 Create a new form, and on that form, place a text box, a grid, a vcr command group, and a command button to break the relation. (The vcr command group can be found in the Buttons.vcx file located in VFP\Samples\Classes.)  In the Load event of the form, add the following code: USE customer IN 0 * Customers.dbf and Orders.dbf can be found in VFP\Samples\Data USE orders IN 0 ORDER cust_id SELECT CUSTOMER SET RELATION TO cust_id INTO orders   In the Init event of the form, add the following code: ThisForm.Text1.ControlSource = "cust_id" ThisForm.Grid1.RecordSource = "orders" ThisForm.Grid1.RecordSourceType = 1   Place the following code in the Click event for the Break command button: SELECT customer SET RELATION TO  thisform.grid1.recordsource='orders' ThisForm.Refresh   In the Unload event of the form add the following code: select customer use select orders use  Open the View window, and run the form.</li> Make a note of the customer id number in the text box, and skip through the first three records.</li> Click the Break command button.</li> Notice that the relation no longer exists in the View window and the only records available in the grid are those that match the current parent record and beyond. No previous records are available.</li></ol>

Additional query words: kbvfp300 kbvfp500 kbvfp600

Keywords: kbbug KB148332

-

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

© Microsoft Corporation. All rights reserved.