How To Create a Report Based on a Query

Last reviewed: March 18, 1998
Article ID: Q157947
3.00 3.00b 5.00 WINDOWS kbui kbhowto

The information in this article applies to:

  • Microsoft Visual FoxPro for Windows, versions 3.0, 3.0b, 5.0

SUMMARY

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

MORE INFORMATION

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

  1. Issue the following command in the command window:

          CREATE TABLE TEST (fld_one C(5), fld_two N(5))
    

  2. Add five records, three of them with "aaa" in fld_one.

  3. Create a report, and add the table to the DataEnvironment.

  4. Drag the fields to the detail band.

  5. Remove the Alias reference from each field in the report.

  6. 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
    
    

  7. In the Destroy method of the DataEnvironment enter CLOSE ALL. (You may leave this out if you do not want to close everything.)

  8. Remove the table from the DataEnvironment.

  9. Save the report as QueryTest.

  10. In the Command window issue either of the following two commands:

           REPORT FORM Querytest to PRINT
           -or-
           REPORT FORM Querytest PREVIEW
    

REFERENCES

For another method of doing this based on a view, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q130122
   TITLE     : How to Add SQL SELECT to the Data Environment of a Report


KBCategory: kbui kbhowto
KBSubcategory: FxtoolReportdes
Additional reference words: 3.00 3.00b 5.00 kbdsd vfoxwin
Keywords : FxtoolReportdes kbhowto kbui
Version : 3.00 3.00b 5.00
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 18, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.