Share via


RemoveItem Method [Access 2003 VBA Language Reference]

Removes an item from the list of values displayed by the specified list box control or combo box control.

expression.RemoveItem(Index)

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

Index  Required Variant. The item to be removed from the list, expressed as either an item number or the list item text.

Remarks

This method is only valid for list box or combo box controls on forms. Also, the RowSourceType property of the control must be set to "Value List".

List item numbers start from zero. If the value of the Index argument doesn't correspond to an existing item number or the text of an existing item, an error occurs.

Use the AddItem method to add items to the list of values.

Example

This example removes the specified item from the list in a list box control. For the function to work, you must pass it a ListBox object representing a list box control on a form and a Variant value representing the item to be removed.

Function RemoveListItem(ctrlListBox As ListBox, _
        ByVal varItem As Variant) As Boolean

    ' Trap for errors.
    On Error GoTo ERROR_HANDLER

    ' Remove the list box item and set the return value
    ' to True, indicating success.
    ctrlListBox.RemoveItem Index:=varItem
    RemoveListItem = True

    ' Reset the error trap and exit the function.
    On Error GoTo 0
    Exit Function

' Return False if an error occurs.
ERROR_HANDLER:
    RemoveListItem = False

End Function

Applies to | ComboBox Object | ListBox Object

See Also | AddItem Method