Selecting the First Item in a ComboBox or ListBox on a Microsoft Access Form
by FMS Development Team
Sample database: SelectFirstItemInList.zip (36 KB)
The Problem
Combo boxes and list boxes are a great way to
control user experience by limiting the values
that a user can choose to a known list.
When working with ComboBoxes and ListBoxes, we often find the need to
select the first item in the list by default. This can be done when the form
loads, or with the contents of the ListBox or ComboBox are changed based on
another selection (see our tip on Cascading
ComboBoxes/ListBoxes).
The Solution
To select the first item, we use the following syntax to set the value of
the control:
Me.ControlName = Me.ControlName.ItemData(0)
Our example database contains a form with a ComboBox containing
ProductCategoties, and a ListBox containing Products.

When we load the form, we want to select the first Category in the list.
Private Sub Form_Load()
' When the form loads, select the first item in the Category ComboBox
Me.cboCategoryName = Me.cboCategoryName.ItemData(0)
' Call the code that updates the Products ListBox based on the selected category
cboCategoryName_AfterUpdate
End Sub
When we change the Category, we want to update the Products list, and
select the first Product in the list:
Private Sub cboCategoryName_AfterUpdate()
' Call the code that updates the Products ListBox based on the selected category
Me.lstProducts.RowSource = "SELECT ProductName " & _
"FROM products " & _
"WHERE CategoryID = " & Nz(Me.cboCategoryName)
' Re-load the list box
Me.lstProducts.Requery
' Select the first Product in the list box
Me.lstProducts = Me.lstProducts.ItemData(0)
End Sub
After updating the RowSource
property, use the list box's
Requery method to re-load the data in the ListBox.
RecordSource versus RowSource
There is sometimes confusion between the terms
RecordSource and RowSource. Both are properties that can
contain a table, query, or SQL string.
- The
RecordSource property
is a form or report property to populate the data that
Microsoft Access displays for that object.
- The
RowSource property
is at the ComboBox or ListBox control level that tells
Microsoft Access what data to display for the control.
It is independent of the data specified by the object's RecordSource.
Resources for Microsoft Access Forms, Combo Boxes and Tabs
|