How to access a report's data environment while the report runs (145816)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 3.0
  • Microsoft Visual FoxPro for Windows 3.0b
  • Microsoft Visual FoxPro for Windows 7.0
  • Microsoft Visual FoxPro 8.0
  • Microsoft Visual FoxPro 9.0 Professional Edition

This article was previously published under Q145816

SUMMARY

This article explains how to access a report's data environment while the report is running. You can use this method in Visual FoxPro 9.0, or you can also use the new Report Listener and take advantage of Visual FoxPro 9.0's event driven printing.

MORE INFORMATION

When you create a report, an associated data environment (DE) is created. The data environment contains information about the tables, views and relations associated with the report.

The data environment is an object, and it is a container for a cursor and a relation object. You can gain access to the DE of a report while it is running, so you can manipulate the its properties and methods.

To gain access to the data environment, you need to be able to reference it as an object. Use the NAME clause on the REPORT FORM command to specify an object's variable name for the data environment as in this example:
   REPORT FORM Samples\Mainsamp\Reports\salessum NAME salessum PREVIEW ;
      NOWAIT
    ** In VFP 7.0, use this line of code:
    **  REPORT FORM HOME(2)+"tastrade\reports\salessum.frx" NAME salessum  PREVIEW ;
    **  NOWAIT
   ?salessum.Name           && Returns DataEnvironment
   ?salessum.Cursor1.Alias  && Returns sales_summary
				
For example, if you want to manually open the tables associated with a report, you can call the OpenTables method of the data environment. The following step-by-step procedure explains how.

Step-by-Step Procedure

  1. Create a new report.
  2. Add the Customer table, located in Samples\Data, to the data environment, and drag it onto the Detail band of the report to create a quick report.
  3. In the DE, set the AutoOpenTables property to false (.F.).
  4. Add a title band to the report, and place a field in the title band. In the field expression, type OpenAll() to call a user-defined function.
  5. Create a program file. Adjust the following code to your needs, and place it in the program file:
       REPORT FORM <reportname> NAME TEST  &&Names the data environment TEST
    
       PROCEDURE openall
       IF <condition>
          TEST.OpenTables      && Calls the OpenTables method of the DE
       ENDIF
       RETURN ""
    						
  6. Save the program, and run it.

Modification Type:MajorLast Reviewed:2/22/2005
Keywords:kbcode KB145816