Problem with sub..._Change

  • Thread starter Thread starter Jacob
  • Start date Start date
J

Jacob

I use a sub to update the options in a listbox based on the selection
of a combobox. I have it set to update when the combobox changes:

Private Sub ComboBoxgroupW_Change()
With UserFormDesign
.ListBoxW.RowSource = .ComboBoxgroupW.Value
End With
End Sub

this is causing problems when the main program is running because
apparently it updates as the main function iterates, and this statement
assigns bad input to rowsource when the function has not completed
running. Is there a better option to use than "Change." Or is there a
way to disable this sub while the program is running? thanks
 
How about the combo's DropButtonClick event. It only gets loaded then when
someone goes to use it.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
I'm sure there are a couple of ways to fix the problem, here's one
way...
Try declaring a public variable where your main code is running and
giving you the problem, for example:


Dim x as integer ' outside of your main code
Sub yourmaincode()
x = 100

the rest of your code

x = 0
End Sub

Then in your ComboBoxgroupW_Change code:

Private Sub ComboBoxgroupW_Change()
If x = 100 Then Exit Sub
With UserFormDesign
.ListBoxW.RowSource = .ComboBoxgroupW.Value
End With
End Sub

Hope this helps you

Sandy
 
I'll give that a try. Thanks!


Bob said:
How about the combo's DropButtonClick event. It only gets loaded then when
someone goes to use it.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Thanks Sandy. that is what I have done right now and it's working. I
just feel like it's a roundabout way of doing things. I guess if it
works it works.
 
I hear ya, but sometimes the simplest routes work the best. Just keep
debugging and looking for the places that fire the change event and see
if you can't tweek the code so that it will only fire when you'd like
it to update the ComboBox.

Good luck

Sandy
 
Back
Top