Iterate through a Combobox's list and select row

  • Thread starter Thread starter Wart
  • Start date Start date
W

Wart

In code I need to iterate through a Combobox's list and then select (click)
on a line. In VB6 I would use something like:
For i = 0 to CBO.ListCount -1
if CBO.List(i) = SomeValue then
CBO.ListIndex = i
Exit For
end if
next

In Access, ListIndex is a read only property. Is there a way to get where I
want to go?
Thanks in advance.
CF
 
Wart said:
In code I need to iterate through a Combobox's list and then select (click)
on a line. In VB6 I would use something like:
For i = 0 to CBO.ListCount -1
if CBO.List(i) = SomeValue then
CBO.ListIndex = i
Exit For
end if
next

In Access, ListIndex is a read only property. Is there a way to get where I
want to go?


Access Combo boxes do mpot have a List property. Check Help
for the Column and ItemData properties.

You can write to the ListIndex property when the combo box
has the focus.

OTOH, you don't have to loop to find the item in the list if
it's the data in the combo's row source with the first
non-zero column width. You can just set the combo's Text
property (also needs the focus).
 
Marshall,
Many thanks for the reply. I figured out what should have been intuitive a
while ago - simply writing to the text property as you said I should.
CF
 
Back
Top