HOWTO: Use More Than One Table in a Combo or List Box (132548)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 3.0
  • Microsoft Visual FoxPro for Windows 5.0
  • Microsoft Visual FoxPro for Windows 6.0

This article was previously published under Q132548

SUMMARY

This article shows by example how to use fields from multiple tables in a combo or list box by placing a SQL SELECT command in the RowSource property.

MORE INFORMATION

Step-by-Step Example

  1. Create a new form.
  2. Open up the Data Environment and place the Products and Orditems tables in it.
  3. Select the Combo box or List box tool from the form[ASCII 146]s Control toolbar, and place a combo or list box on the form.
  4. Set the FirstElement property to 1, the NumberOfElements property to 1, and the RowSourceType property to 3-SQL Statement.
  5. Add a SQL statement such as the following in the RowSource property:
          SELECT DISTINCT(padl(alltrim(orditems.product_id),2," ")) + ;
             "....." + products.prod_name AS prod FROM orditems, products ;
             INTO CURSOR items ;
             WHERE products.product_id = orditems.product_id ;
             ORDER BY prod
    						
  6. Run the form, and click the combo box down arrow to open up the list. The Product_id from the Orditems table will be the first thing in each line item with periods leading over to the product name (Prod_name) derived from the Products table.

Modification Type:MinorLast Reviewed:7/13/2004
Keywords:kbcode kbhowto KB132548