Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
ComboBox Problem with ListIndex
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
ComboBox Problem with ListIndex
try changing the inex to -1 which will deselect the active row in the combobox
UserForm1.ComboBox1.ListIndex = -1 "donwb" wrote: 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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
ComboBox Problem with ListIndex
Yes. Thanks Joel
"Joel" wrote in message ... try changing the inex to -1 which will deselect the active row in the combobox UserForm1.ComboBox1.ListIndex = -1 "donwb" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Userform problem (Listindex) | Excel Programming | |||
Userform problem (Listindex) | Excel Discussion (Misc queries) | |||
Listindex strange problem | Excel Programming | |||
listbox listindex problem | Excel Programming | |||
listindex | Excel Programming |