Microsoft KB Archive/157947

= How to create a report that is based on a query in Visual FoxPro =

Article ID: 157947

Article Last Modified on 2/12/2007

-

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 6.0 Professional Edition
 * Microsoft Visual FoxPro 7.0 Professional Edition
 * Microsoft Visual FoxPro 8.0 Professional Edition
 * Microsoft Visual FoxPro 9.0 Professional Edition

-



This article was previously published under Q157947



SUMMARY
It is possible to create a report based on a query by placing the SELECT-SQL statement in the Init method of the DataEnvironment.



MORE INFORMATION
Use the following steps to create a report based on a query:

  Issue the following command in the command window: CREATE TABLE TEST (fld_one C(5), fld_two N(5))  Add five records, three of them with "aaa" in fld_one. Create a report, and add the table to the DataEnvironment. Drag the fields to the detail band. Remove the Alias reference from each field in the report.  In the Init method of the DataEnvironment enter the following code: USE test && Only need if the table is not already open. SELECT fld_one, fld_two ; FROM Test where fld_one= "aaa" ; INTO CURSOR Temp  In the Destroy method of the DataEnvironment enter CLOSE ALL. (You may leave this out if you do not want to close everything.)</li> Remove the table from the DataEnvironment.</li> Save the report as QueryTest.</li>  In the Command window issue either of the following two commands: REPORT FORM Querytest to PRINT -or- REPORT FORM Querytest PREVIEW </li></ol>

<div class="references_section">