referencing a Combo box index by text

  • Thread starter Thread starter Anja
  • Start date Start date
A

Anja

Hi everyone,

I have a Combo Box that contains a list of strings.

Now, I do a database query that returns me a string (which I know will
be there in the combo box). is there a way to ask the Combo box to
change its index... but not by giving it a number but to give it the
string that is the value at the required index...

Cheers,
Anja
 
Well, it seems that whenever I set the value of the combo box using the
..Value property, it just does not like it:

So, I do something like this:

Category list is the combo box...

I am looping through all the items and setting the value when I find a
matching one...


For counter = 0 To CategoryList.ListCount - 1
If CategoryList.Column(1, counter) =
rstLookup.Fields![Name] Then
CategoryList.Value = CategoryList.Column(1,
counter)
Exit For
End If
Next counter

It runs this code fine but when I click on the combo box, I get a
dialog box saying the value I have enteretd is not valid. I know this
value exists in the combo box...

Is there a simple way how I can set the index of the currently selected
item in the combo box??? Why has MS made the ListIndex property read
only?????

Cheers,
Anja
 
You cannot change the index value for an item in a combo. It will change if
you change the order of the combo's row source, but I don't think that is
what you are after.

If what you are trying to do is make the current value of the combo equal to
what your field is, then all you have to do is:

Me.CategoryList = rstLookup.Fields![Name]

If you need the the index value of the selected item, then you would add the
following line:

intListVal = Me.CategoryList.ListIndex

If that is not what you are attempting, please post back with a description
of what you are trying to do and we can see if there is a way to accomplish
it.
 

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

Back
Top