ComboBox Problem with ListIndex

D

donwb

Win XP, Excel 2003
I have a ComboBox with 7 rows in the drop down mode.
Before clicking the drop down button, the initial CB window is blank.
In the set up code for the CB I then inserted the following line:-
UserForm1.ComboBox1.ListIndex = 0
which I had hoped would make the initial CB window show the first line of
the drop down.
However, as soon as the the above code is executed, the programme jumps to
the CB's
Click event code and an error occurs.
The Initialize code is:-

Private Sub UserForm_Initialize()
Dim AlarmArray(7, 7)
For D = 1 To 7
AlarmDaysBefore = D & " " & "days "
AlarmArray(D, 0) = AlarmDaysBefore
Next D
UserForm1.ComboBox1.List() = AlarmArray
UserForm1.ComboBox1.Style = fmStyleDropDownList
UserForm1.ComboBox1.ListIndex = 0
End Sub

and the CB Click code is:-

Private Sub ComboBox1_Click()

MyIndex = ComboBox1.ListIndex
MyText = ComboBox1.List(MyIndex, 0)
Call SetAlarm
Unload UserForm1

End Sub

I have tried EnableEvents = false to prevent the uncommanded jump to the
click event,
but it has no effect.
I'm baffled - help please
donwb
 
J

Joel

try changing the inex to -1 which will deselect the active row in the combobox

UserForm1.ComboBox1.ListIndex = -1
 

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