ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ComboBox Problem with ListIndex (https://www.excelbanter.com/excel-programming/431234-combobox-problem-listindex.html)

donwb

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






joel

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







donwb

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










All times are GMT +1. The time now is 09:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com