Check if item is present in combo without trigger the change event

F

fms

I want to fill a combobox with unique items.
What is the easiest way to check if an item is already there, without
triggering the change event?

A simple way is to loop through the combo by setting the listindex from min
to max, and check if cbo.value = string, but this triggers the change event.
 
C

Cindy M -WordMVP-

Hi Fms,
I want to fill a combobox with unique items.
What is the easiest way to check if an item is already there, without
triggering the change event?

A simple way is to loop through the combo by setting the listindex from min
to max, and check if cbo.value = string, but this triggers the change event.
WHY are you using the Change event? To do what?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
F

fms

I have to combo's: cbo1 and cbo2. Changes in cbo1 shall change cbo2's
rowsource.
This works fine, except when I want to check if an item is a valid member of
cbo1's list.

If I set combo1.style = fmStyleDropDownCOMBO, I can use:
cbo1.text = item_to_check
if cbo1.listindex = -1 then <item_to_check not present cbo1>

However, if combo1.style = fmStyleDropDownLIST (as in this case) the only
way to find out if item_to_check is present in cbo1 is to check every item
in cbo1. I think. And this triggers the change event, and cbo2's rowsource
changes n times.
Is there a way to disable the change event from triggering? Or another way
to find out if item_to_check is present in cbo1's list?

Fred
 
C

Cindy M -WordMVP-

Hi Fms,
I have to combo's: cbo1 and cbo2. Changes in cbo1 shall change cbo2's
rowsource.
This works fine, except when I want to check if an item is a valid member of
cbo1's list.
Since you mention rowsource, I'm guessing you're working in Excel? (Word can't
support rowsource, and this IS a Word.vba group :)) You'll be better off
asking questions in the application-specific group...

The most "obvious" answer that comes to my mind is to either store the list of
items in the one combo box in an array, and compare the array. Or store the
list in a hidden area of the workbook, and compare that.

The other approach would be to simply not use the Change event, but execute
code on exiting the field.

HOWEVER, when I loop through a combobox's list the Change event does not
trigger. So I do wonder how you're doing that. I use:

For i = 0 To ComboBox1.ListCount - 1
Debug.Print ComboBox1.List(i)
Next
If I set combo1.style = fmStyleDropDownCOMBO, I can use:
cbo1.text = item_to_check
if cbo1.listindex = -1 then <item_to_check not present cbo1>

However, if combo1.style = fmStyleDropDownLIST (as in this case) the only
way to find out if item_to_check is present in cbo1 is to check every item
in cbo1. I think. And this triggers the change event, and cbo2's rowsource
changes n times.
Is there a way to disable the change event from triggering? Or another way
to find out if item_to_check is present in cbo1's list?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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