Change the selected index of an Access combobox using VBA (1 Viewer)

Michael.Koppelgaard

New member
Local time
Today, 10:34
Joined
Apr 19, 2022
Messages
17
Hi everybody
I'm trying to change the selected index/item of an Access combobox using VBA.
I tried this
Me.Combo14.ListIndex(1) = True
but listindex is a read-only property.
What can I do?

Michael
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:34
Joined
May 7, 2009
Messages
19,246
use ItemData

Me.Comb14 = Me.Combo.ItemData(1)
 

Michael.Koppelgaard

New member
Local time
Today, 10:34
Joined
Apr 19, 2022
Messages
17
Hi arnelgp
My problem is that combo14 consists of 2 columns. If I only change the value of the combobox (as I think your code do) I will not change the index.
I need to change the index also.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:34
Joined
May 7, 2009
Messages
19,246
it does change the Index (ListIndex).
when there is no selection in the combo, ListIndex = -1.
when first item is selected, ListIndex = 0,
second item, ListIndex = 1

so ListIndex starts with 0 and end with ListCount-1.

so your code, show the ListIndex after you use ItemData():

Me.Comb14 = Me.Combo.ItemData(1)
Msgbox Me.Comb14.ListIndex
 

Users who are viewing this thread

Top Bottom