How to print a report that is based on selections in a list in Visual FoxPro (147310)



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 6.0
  • 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 Q147310

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:

    1. In the Data tab, set the RowSourceType to 2-Alias and the RowSource to customer.
    2. 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
    						

Modification Type:MajorLast Reviewed:2/17/2005
Keywords:kbcode KB147310