AddItem Method
Collapse the table of content
Expand the table of content
The document is archived and information here might be outdated

AddItem Method [Access 2003 VBA Language Reference]

Office 2003

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

expression.AddItem(Item, Index)

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

Item  Required String. The display text for the new item.

Index  Optional Variant. The 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 Index 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.

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.

Function AddItemToBeginning(ctrlComboBox As ComboBox, _
        ByVal strItem As String)

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

End Function
		




Show:
© 2016 Microsoft