Microsoft KB Archive/140298

= How to print all the records for a single field within a data grouping before you print records for the next field in Visual FoxPro =

Article ID: 140298

Article Last Modified on 2/2/2005

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 7.0 Professional Edition

-



This article was previously published under Q140298



SUMMARY
In the Visual FoxPro Report Designer, you may want to print all the records for a single field within a data grouping before printing records for the next field. This article gives you the steps to accomplish this.



MORE INFORMATION
To print all records of a particular field before printing the records of another field using the Report Designer, the report must be set up in a certain way. This example uses the Testdata!Customer table in the Vfp\Samples\Data subdirectory. Another field can be substituted for Country as the Grouping Field in the code example and field expressions.

These directions must be followed precisely to get the desired behavior.

Step-by-Step Example
 Create a user-defined function (UDF) to handle the processing:

  Type the following command in the Command window to create a program to hold the UDF: MODIFY COMMAND countkid.prg   Enter the following code in Countkid.prg: PARAMETERS cFldname, cCountry cPassback="" nPerposn=AT(".",cFldname) cFldname=UPPER(SUBSTR(cFldname,nPerposn+1,LEN(cFldname)-nPerposn)) =AFIELDS(acFnames) nAfldpos=ASUBSCRIPT(acFnames,ASCAN(acFnames,cFldname),1) SELECT * FROM CUSTOMER WHERE COUNTRY=cCountry INTO ARRAY aMyray anRow=ALEN(aMyray,1) FOR nI=1 TO anRow cPassback=cPassback+ALLTRIM(aMyray(nI,nAfldpos))+CHR(13) ENDFOR RETURN cPassback   In the Customer.dbf table, add an index tag Country for the field Country if it does not already exist. This will be used in this example for the data grouping. Create a report, and add the Customer table to the Data Environment (DE). Set the Order property of the Cursor object within the DE to Country. Set up a Data Grouping in the report on the Country field.</li>  Add a field to the report within the detail band. In the expression for this field, enter: IIF(nMycount<1,countkid(" ",Country),"") NOTE: The " " should contain the name of the field you want to print. For example, use Customer.Cust_id or Cust_id. </li> In the Report Expression dialog box, click the Float option, and select the Stretch with Overflow check box.</li> Click the Print When button, and in the Print When dialog box, select No under Print Repeated Values and select the Remove Line if Blank check box for each field expression.</li>  Create a report variable called nMycount, and set the following values: <pre class="fixed_text">  Value to Store = 0 Initial Value = 0 Reset = Customer.Country Calculation = Sum Check the Release after Report check box. </li> Place additional field expressions (in Step 4) for each field you want to print. Each field expression should be placed below the preceding field expression in the detail band. Within each group, all values for each field expression will print before the all the values for each subsequent field expression.</li></ol>

General Notes

 * The fieldname in quotation marks is passed to the UDF along with the name of the grouping field without quotation marks. In the previous example, "Customer.Cust_id" or "Cust_id" is passed as the first parameter, and Country is passed as the next parameter.
 * The array functions allow data manipulation within the report without affecting the original data. You build an expression with carriage returns that you then pass back to the report to print. The variable and IIF ensure that this UDF will run once only for each record processed.

Additional query words: VFoxWin

Keywords: KB140298

-

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

© Microsoft Corporation. All rights reserved.