COMBOBOX reaction

COMBOBOX reaction

Jedimaster
Collaborator Collaborator
504 Views
2 Replies
Message 1 of 3

COMBOBOX reaction

Jedimaster
Collaborator
Collaborator

I have a VBA routine with a userform that has a combobox in it.

 

I did not know which to use

The default seems to be

Private Sub ComboBox1_Change

 

But I also thought about

Private Sub ComboBox1_Click

 

With that said I, am trying to  to get the routine to only react when the ComboBox is used. However, the seem to invoke on initialization of the form instead of when the combobox is being used.

 

0 Likes
505 Views
2 Replies
Replies (2)
Message 2 of 3

Hallex
Advisor
Advisor

Use change event but after initializinf the form

set index to -1:

{code}

Private Sub UserForm_initialize()

' fill combo with your values:
Dim i
For i = 1 To 10
ComboBox1.AddItem i
Next
ComboBox1.ListIndex = -1
End Sub


Private Sub ComboBox1_Change()


If ComboBox1.ListIndex <> -1 Then
MsgBox ComboBox1.Text
End If
End Sub

{code}

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 3 of 3

Jedimaster
Collaborator
Collaborator

Works good... The only thing is now you lose th ability to set a default.

0 Likes