ComboBox.Clear method calling ComboBox_Change event?

G

Guest

I need to clear out a ComboBox in order to prep it for later use. At the
current time, it has 200 entries. Eventually it will have over 2000. Removing
each item individually is not a desirable option. It takes a while to load
it. I'd hate for it to take that long to unload.

Problem is, when I execute ComboBox.Clear, it appears to call the
ComboBox_Change() event. Since there is nothing in the ComboBox, it calls the
error handler that checks for unknown entries (ie: typing your own data in
the BomboBox).

Is there a way to execute the .Clear method without calling the _Change()
event?
 
G

Guest

If you don't want users to be able to type in values that are not in the
combo box list, you can set the combo box style to frmStyleDropDownList.

When you clear the combo box list and the combo box currently has a selected
value, the Change event will fire. To avoid executing your code in the
change event, maybe you can exit out of the sub if the combo box has no value
selected. For example:

Private Sub ComboBox1_Change()
If ComboBox1.ListIndex = -1 Then Exit Sub

'put your code below
End Sub
 
G

Guest

The code sample will work well.

I was afraid to try "frmStyleDropDownList", thinking it would force the
users to click and scroll through up to 2000 items. But it worked quite well!

Thank you!
 

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