ListIndex Property

Applies to

ComboBox Object
ListBox Object

You can use the ListIndex property to determine which item is selected in a list box (list box: A control that provides a list of choices. A list box consists of a list and an optional label.) or combo box (combo box: A control used on a form that provides the combined functionality of a list box and a text box. You can type a value in a combo box, or you can click the control to display a list and then select an item from that list.). Read/write Long.

expression.ListIndex

expression Required. An expression that returns one of the objects in the Applies To list.

Remarks

The ListIndex property is an integer from 0 to the total number of items in a list box or combo box minus 1. Microsoft Office Access 2007 sets the ListIndex property value when an item is selected in a list box or list box portion of a combo box. The ListIndex property value of the first item in a list is 0, the value of the second item is 1, and so on.

This property is available only by using a macro (macro: An action or set of actions that you can use to automate tasks.) or Visual Basic for Applications (VBA) (Visual Basic for Applications (VBA): A macro-language version of Microsoft Visual Basic that is used to program Microsoft Windows-based applications and is included with several Microsoft programs.) code. You can read this property only in Form view (Form view: A view that displays a form to show or accept data. Form view is the primary means of adding and modifying data in tables. You can also change the design of a form in this view.) and Datasheet view (Datasheet view: A view that displays data from a table, form, query, view, or stored procedure in a row-and-column format. In Datasheet view, you can edit fields, add and delete data, and search for data.). This property is read-only and isn't available in other views.

The ListIndex property value is also available by setting the BoundColumn property to 0 for a combo box or list box. If the BoundColumn property is set to 0, the underlying table field to which the combo box or list box is bound will contain the same value as the ListIndex property setting.

List boxes also have a MultiSelect property that allows the user to select multiple items from the control. When multiple selections are made in a list box, you can determine which items are selected by using the Selected property of the control. The Selected property is an array of values from 0 to the ListCount property value minus 1. For each item in the list box the Selected property will be True if the item is selected and False if it is not selected.

The ItemsSelected collection also provides a way to access data in the selected rows of a list box or combo box.

Example

To return the value of the ListIndex property, you can use the following:

Dim l As Long
l = Forms().Controls(.
      

To set the ListIndex property value, you can use the following:

Forms(formname).Controls(controlname).SetFocus
Forms().Controls(). = 
         

Where formname and controlname are the names of the form and list box or combo box control, respectively, expressed as String values, and index is the index value of the item.

 
 
Applies to:
Access 2007