PC Review


Reply
Thread Tools Rate Thread

ComboBox Problem with ListIndex

 
 
donwb
Guest
Posts: n/a
 
      17th Jul 2009
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 With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      17th Jul 2009
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 With Quote
 
donwb
Guest
Posts: n/a
 
      18th Jul 2009
Yes. Thanks Joel

"Joel" <(E-Mail Removed)> wrote in message
news:82EDEAAD-04A2-4A63-914A-(E-Mail Removed)...
> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How to select the first combobox item (ie. Set Combobox.ListIndex = 0) Dirk Goldgar Microsoft Access Form Coding 0 11th Aug 2009 03:10 PM
ComboBox ListIndex changes to -1 AirPo Microsoft Access Forms 3 26th Mar 2006 05:36 PM
Combobox ListIndex Bryan Hughes Microsoft Access Forms 4 29th Oct 2003 11:06 PM
Re: ListIndex not working in ComboBox Herfried K. Wagner [MVP] Microsoft Dot NET 1 21st Aug 2003 03:11 AM
Re: ListIndex not working in ComboBox cj Microsoft Dot NET 0 20th Aug 2003 10:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:47 AM.