ListBox.ItemData property (Access)

The ItemData property returns the data in the bound column for the specified row in a list box. Read-only Variant.

Syntax

expression.ItemData (Index)

expression A variable that represents a ListBox object.

Parameters

Name Required/Optional Data type Description
Index Required Long The row in the combo box or list box containing the data that you want to return. Rows in combo boxes and list boxes are indexed starting with zero. For example, to return the item in the sixth row of a combo box, you'd specify 5 for the rowindex argument.

Remarks

The ItemData property enables you to iterate through the list of entries in a combo box or list box. For example, suppose you wanted to iterate through all of the items in a list box to search for a particular entry. Use the ListCount property to determine the number of rows in the list box, and then use the ItemData property to return the data for the bound column in each row.

You can also use the ItemData property to return data only from selected rows in a list box. You can iterate through the ItemsSelected collection to determine which row or rows in the list box have been selected, and then use the ItemData property to return the data in those rows. You must set the MultiSelect property of the list box to Simple or Extended to enable the user to select more than one row at a time.

Use the Column property to return data from a specified row and column, even if the specified column isn't the bound column.

Example

The following example prints the value of the bound column for each selected row in the list box EmployeeList on an Employees form. The list box's MultiSelect property must be set to Simple or Extended.

Sub RowsSelected() 
 Dim ctlList As Control, varItem As Variant 
 
 ' Return Control object variable pointing to list box. 
 Set ctlList = Forms!Employees!EmployeeList 
 ' Enumerate through selected items. 
 For Each varItem in ctlList.ItemsSelected 
 ' Print value of bound column. 
 Debug.Print ctlList.ItemData(varItem) 
 Next varItem 
End Sub

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.