This documentation is archived and is not being maintained.

ComboBox.AddItem Method

Office 2007
Adds a new item to the list of values displayed by the specified combo box control.

Syntax

expression.AddItem(Item, Index)

expression   A variable that represents a ComboBox object.

Parameters

NameRequired/OptionalData TypeDescription
ItemRequiredStringThe display text for the new item.
IndexOptionalVariantThe position of the item in the list. If this argument is omitted, the item is added to the end of the list.

Remarks

The RowSourceType property of the specified control must be set to "Value List".

This method is only valid for list box or combo box controls on forms.

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

For multiple-column lists, use semicolons to delimit the strings for each column (for example, "1010;red;large" for a three-column list). If the Item argument contains fewer strings than columns in the control, items will be added starting with the left-most column. If the Item argument contains more strings than columns in the control, the extra strings are ignored.

Use the RemoveItem method to remove items from the list of values.

Example

This example adds an item to the end of 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 String value representing the text of the item to be added.

Visual Basic for Applications
Function AddItemToEnd(ctrlListBox As ListBox, _
        ByVal strItem As String)

    ctrlListBox.AddItem Item:=strItem

End Function

This example adds an item to the beginning of the list in a combo box control. For the function to work, you must pass it a ComboBox object representing a combo box control on a form and a String value representing the text of the item to be added.

Visual Basic for Applications
Function AddItemToBeginning(ctrlComboBox As ComboBox, _
        ByVal strItem As String)

    ctrlComboBox.AddItem Item:=strItem, Index:=0

End Function


Show: