Microsoft KB Archive/164870

= How To Apply, Remove a Filter from Form's DataEnvironment =

Article ID: 164870

Article Last Modified on 6/29/2004

-

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 Q164870



SUMMARY
The following article demonstrates how to filter records in the DataEnvironment of a form and how to remove the filter.



MORE INFORMATION
 Create a new form and add the Customer.dbf table from the directory :\VFP\samples\mainsamp\data to the DataEnvironment (from the view menu, select Data Environment. In Visual FoxPro 6.0, Customer.dbf is in the Microsoft Visual Studio\Common\Samples\Data folder. From the DataEnvironment menu, select Add and then select the customer table. Drag the customer_id field, the company_name field, and the country field to the form and add three command buttons to the form.  In the click event of the first command button, place the following code:       ThisForm.DataEnvironment.cursor1.filter = "country = 'Germany'"      ThisForm.Refresh                              In the click event of the second button place the following code:        ThisForm.DataEnvironment.cursor1.filter = ".T."      ThisForm.Refresh  && Note: Record position is lost with this code. - or - STORE ThisForm.DataEnvironment.cursor1.alias to xVar SELECT &xVar SET FILTER to     ThisForm.Refresh  && Note: record position is not lost.   In the click event of the third button place the following code: SKIP IF EOF GO BOTTOM ENDIF Thisform.Refresh  Save the form and run it. Click the button Command1 to apply the filter, and then click the button Command2 to remove the filter.</li></ol>

<div class="references_section">