views:

247

answers:

2

I have an application written in VBA for Excel that takes in a live data feed. Whenever there is a change in the data, various events are triggered within VBA.

I also have some UserForms with ComboBoxes on them. My problem is that when I click the down arrow on the ComboBox and try to make a selection, the moment I get an update from the data feed, the ComboBox resets. What I would like to do is pause the events while I'm making my selection in the ComboBox and unpause it when I'm done.

I feel like this should be a simple thing to do but I'm just not sure which functions I should be putting my code into. Any help would be greatly appreciated. Thanks.

+1  A: 

Try this to turn off:

application.enableevents = false

And this to turn back on:

application.enableevents = true

guitarthrower
So, I'm assuming I would set Application.EnableEvents to false inside the DropDownArrow procedure in the ComboBox, but I don't want the Events to be re-enabled until after a selection has been made
Shaka
It'd help to see some of your code to really know what is going on. The real question is why does the combobox reset? can you post the code?
guitarthrower
I was able to find the issue. I had a function written to update the userform. Apparently that function also reset the ComboBox. By limiting calls to the function, I was able to resolve the issue. Thanks for pointing me in the right direction.
Shaka
+1  A: 

Maybe you can put a flag to bypass the update event on your combobox until a selection is made.

Private bLock as boolean  ' declare at module level

' When a user clicks on the combobox
Private Sub DropDownArrow_Click()  ' or cboComboBox_Click()
    bLocked = True
End Sub

' This procedure is the one that does the updating from the data source.
' If the flag is set, do not touch the comboboxes.
Private Sub subUpdateComboBoxes()
    If Not bLocked then
        ' Update the comboboxes
    End If
End Sub


' When the selection is made, or the focus changes from the combobox.
' check if a selection is made and reset the flag.
Private Sub cboComboBox_AfterUpdate()  ' Or LostFucus or something else
    if Format(cboComboBox.Value) <> vbNullString Then
        bLocked = False
    End If
End Sub

Hope that helps.

Marcand
I was able to figure out what was causing the ComboBox to reset but I definitely like your solution because the act of clicking on the down arrow actually pauses the updates. Thanks for the suggestion.
Shaka