How to Print a Report Based On Selections in a List

ID: Q147310

3.00 3.00b WINDOWS

 kbhowto

The information in this article applies to:

SUMMARY

This article shows by example how to present the user with a form containing a multiple select list from a field in a table, and then print a report that contains only the selected records.

MORE INFORMATION

Step-by-Step Example

This example uses the Customer table from Testdata.dbc database in the \Samples\Data subdirectory.

1. Create a new report. Add the Customer table to the Data Environment, and

   choose Quick Report from the Report Menu. Accept the defaults for a
   Quick Report. Save the report as CustRepo.

2. Create a new form, and add the Customer table to the Data Environment.

3. Add a List to the form. In the Properties Sheet of the List do the

   following:

   a. In the Data tab, set the RowSourceType to 2-Alias and the RowSource
      to customer.cust_id.

   b. In the Other tab, set MultiSelect to true (.T.) and the Name to
      lstCust_id.

4. Add a new property to the form. In the New Property dialog box, type:

   achosen[1]

5. Add a command button to the form. Type the following code into its
   Click event:

   local lnCounter
   lnCounter = 0
   DIMENSION ThisForm.achosen[ThisForm.lstCust_id.ListCount]
   WITH ThisForm
      FOR i = 1 TO .lstCust_id.ListCount
         IF .lstCust_id.Selected(i)
            lnCounter = lnCounter + 1
            .achosen[lnCounter] = .lstCust_id.List[i]
         ENDIF
      ENDFOR
   ENDWITH
   IF lnCounter = 0
     WAIT WINDOW "No Records Chosen !"
   ELSE
      DIMENSION ThisForm.achosen[lnCounter]
      REPORT FORM CustRepo FOR ASCAN(ThisForm.achosen,cust_id) > 0 PREVIEW
   ENDIF

Additional reference words: 3.00 3.00b VFoxWin KBCategory: kbhowto KBSubcategory: FxprgGeneral
Keywords          : kbcode FxprgGeneral 
Version           : 3.00 3.00b
Platform          : WINDOWS

Last Reviewed: May 22, 1998