Share via


Allowing Users to Add Items to a List Box

In addition to allowing users to select items from a list box, you can make it possible for users to interactively add items to a list.

To add items to a list interactively

In the following example, when the user presses ENTER, the code in the KeyPress event of a text box adds the text in the text box to the list box and clears the text in the text box:

LPARAMETERS nKeyCode, nShiftAltCtrl
IF nKeyCode = 13   && Enter Key
   THISFORM.lstAdd.AddItem(This.Value)
   THIS.Value = ""
ENDIF

Allowing Users to Enter Data into a Table from a List

If the ControlSource property is set to a field, whatever the user selects in the list is written to the table. This is an easy way to help ensure the integrity of the data in your table. While the user can still enter the wrong data, an illegal value cannot be entered.

For example, if you have a list of states or counties for a user to choose from, the user cannot enter an invalid state or county abbreviation.

Allowing Users to Go to a Record by Picking a Value in a List

Often, you want to let users select the record they want to view or edit. For example, you could provide users with a list of customer names. When the user selects a customer from the list, you select that customer's record in the table and display customer information in text boxes on the form. You can do this several ways, depending on the source of data in your form.

RowSourceType Selecting the appropriate record
2 - Alias
6 - Fields
When the user chooses a value in the list, the record pointer is set automatically to the desired record. Issue THISFORM.Refresh in the InteractiveChange event of the list to show the new values in other controls on the form.
0 - None
1 - Value
3 - SQL Statement
4 - QPR
5 - Array
In the InteractiveChange event, select the table that has the record with the desired values, and then search for the desired value. For example, if the RowSource holds customer identification numbers from the customer table, use this code:
SELECT customer
LOCATE FOR THIS.Value = cust_id
THISFORM.Refresh

See Also

Allowing Users to Select Multiple Items in a List Box | Refreshing a One-to-Many Display Based on a List Value | Using Controls | Displaying Child Records in a List | Controls and Objects