Iterate through a Combobox's list and select row

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
 
M

Marshall Barton

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).
 
W

Wart

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top