Allow Users to Choose List Values Sample
File: ...\Samples\Solution\Forms\Datalook.scx
This sample illustrates providing users with a set of values, selected from another table, in a list box and in a drop-down list box. The value the user chooses is stored in the current table.
It is often more convenient for a user to choose from a list of predetermined values, and, of course, you minimize the risk that the user will mistype a value. Setting a few list box properties is all that is required to provide this capability. For example, the following properties were set for cboEmp_id on the Using Combo Box page:
Property | Setting |
---|---|
BoundColumn | 2 |
ColumnCount | 2 |
ControlSource | orders.emp_id |
RowSource | SELECT DISTINCT ALLTRIM( employee.first_name) + " " + ALLTRIM( employee.last_name) , EMP_ID FROM employee INTO CURSOR cEmpCombo ORDER BY first_name |
RowSourceType | 3 – SQL Statement |
Rather than having the user choose an employee id number from the drop-down list, the SELECT statement makes it possible for you to show the user the employees' first and last names.
Because the SELECT statement creates a cursor, code in the Destroy event closes the cursor.
IF USED("cEmpCombo") THEN
USE IN cEmpCombo
ENDIF