PC Review


Reply
Thread Tools Rate Thread

Combo box change event fires twice

 
 
Smurfette18
Guest
Posts: n/a
 
      20th Dec 2007
Hello,

I have combo box that allows users to select from a list or enter a
value freeform. I also have a change event for this combo box.
Everything works fine when the user selects from the list, but when he
or she enters a value by hand, the change event sometimes fires twice
for no apparent reason. For instance, if you select "0" from the
list, it fires once, but if you type "0" directly in the box, it fires
twice. I already tried disabling events before my code and re-
enabling them after it runs, but that did not work. Any help would be
appreciated.

Thanks!
 
Reply With Quote
 
 
 
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      20th Dec 2007
The Change event of a ComboBox gets fired only when the text is manually
changed... not from selecting from the list. I suspect you have code in your
Change event which you think is doing something that actually is happening
automatically; hence, when you type into the text field, whatever happens
automatically takes place and then something in your Change event code makes
it happen again. I can't tell you any more than that because you didn't post
your code for us to look at.

Rick


"Smurfette18" <(E-Mail Removed)> wrote in message
news:0f220c1d-ccef-4cb7-ae49-(E-Mail Removed)...
> Hello,
>
> I have combo box that allows users to select from a list or enter a
> value freeform. I also have a change event for this combo box.
> Everything works fine when the user selects from the list, but when he
> or she enters a value by hand, the change event sometimes fires twice
> for no apparent reason. For instance, if you select "0" from the
> list, it fires once, but if you type "0" directly in the box, it fires
> twice. I already tried disabling events before my code and re-
> enabling them after it runs, but that did not work. Any help would be
> appreciated.
>
> Thanks!


 
Reply With Quote
 
Smurfette18
Guest
Posts: n/a
 
      20th Dec 2007
Rick,

Thanks for your response. It doesn't seem to matter what code I have
in the change event. To troubleshoot the problem I commented out my
code down to this (the combo box is originally set to the default
value 10):

Private Sub ComboBox1_Change()

Dim TestVar as Variant
TestVar = 6

End Sub

I played around with this for a bit, and it seems the problem is
related to the MatchEntry property. If MatchEntry is set to "1 -
fmMatchEntryComplete", the event doesn't fire when I change the
default value to zero manually (it does fire as it should when I enter
any other number by hand or select a value from the list). After this
first peculiar no-fire, it works fine. When MatchEntry is set to "2 -
fmMatchEntryNone", the event fires only once if I select an item from
the list or enter a value manually after entering the prior value
manually. The first time I enter a value manually after selecting the
prior value from the list, the event fires twice for some strange
reason. I would like to keep MatchEntry set to "None", but I need to
get this event to stop firing when it shouldn't.


On Dec 19, 11:08 pm, "Rick Rothstein \(MVP - VB\)"
<rickNOSPAMn...@NOSPAMcomcast.net> wrote:
> The Change event of a ComboBox gets fired only when the text is manually
> changed... not from selecting from the list. I suspect you have code in your
> Change event which you think is doing something that actually is happening
> automatically; hence, when you type into the text field, whatever happens
> automatically takes place and then something in your Change event code makes
> it happen again. I can't tell you any more than that because you didn't post
> your code for us to look at.
>
> Rick
>
> "Smurfette18" <timothy.c.dani...@gmail.com> wrote in message
>
> news:0f220c1d-ccef-4cb7-ae49-(E-Mail Removed)...
>
>
>
> > Hello,

>
> > I have combo box that allows users to select from a list or enter a
> > value freeform. I also have a change event for this combo box.
> > Everything works fine when the user selects from the list, but when he
> > or she enters a value by hand, the change event sometimes fires twice
> > for no apparent reason. For instance, if you select "0" from the
> > list, it fires once, but if you type "0" directly in the box, it fires
> > twice. I already tried disabling events before my code and re-
> > enabling them after it runs, but that did not work. Any help would be
> > appreciated.

>
> > Thanks!- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
Tim Zych
Guest
Posts: n/a
 
      20th Dec 2007
> The Change event of a ComboBox gets fired only when the text is manually
> changed... not from selecting from the list.


I don't think so Rick. If you create a sample form/cbo and try it out you
should see. Type in a value, or select from the list in any way, and the
change event is triggered. The help file has been updated, I believe, to
include a lot more details about the control and the change/click events
than prior versions documented.

----------------------------------------------------------
From the help file in XL2003, Combobox control -> Events ->
------------------
Change event:
------------------
The Change event occurs when the setting of the Value property changes,
regardless of whether the change results from execution of code or a user
action in the interface.
Note In some cases, the Click event may also occur when the Value property
changes. However, using the Change event is the preferred technique for
detecting a new value for a property.
----------------------------------------------------------

Private Sub ComboBox1_Change()
MsgBox "change"
End Sub

Private Sub UserForm_Initialize()
With Me.ComboBox1
.AddItem "a"
.AddItem "b"
.AddItem "c"
End With
End Sub


Tim Zych
SF, CA


"Rick Rothstein (MVP - VB)" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> The Change event of a ComboBox gets fired only when the text is manually
> changed... not from selecting from the list. I suspect you have code in
> your Change event which you think is doing something that actually is
> happening automatically; hence, when you type into the text field,
> whatever happens automatically takes place and then something in your
> Change event code makes it happen again. I can't tell you any more than
> that because you didn't post your code for us to look at.
>
> Rick
>
>
> "Smurfette18" <(E-Mail Removed)> wrote in message
> news:0f220c1d-ccef-4cb7-ae49-(E-Mail Removed)...
>> Hello,
>>
>> I have combo box that allows users to select from a list or enter a
>> value freeform. I also have a change event for this combo box.
>> Everything works fine when the user selects from the list, but when he
>> or she enters a value by hand, the change event sometimes fires twice
>> for no apparent reason. For instance, if you select "0" from the
>> list, it fires once, but if you type "0" directly in the box, it fires
>> twice. I already tried disabling events before my code and re-
>> enabling them after it runs, but that did not work. Any help would be
>> appreciated.
>>
>> Thanks!

>



 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      20th Dec 2007
You are absolutely right... what I said does not apply to the VBA ComboBox
in the Office product line. It *does* apply to the compiled VB world's
ComboBox and I made the mistake of assuming the same base control would be
behind both implementations. But, as your message points out, I was wrong in
that belief and I apologize if I have misled anyone because of it.

I do have to say, though, that having the Change event fire whether the text
is changed *or* the list is Clicked seems to make it a less useful event
than the one in the compiled VB world. Over there, a Click event is reserved
solely for a manual selection from the list itself and the Change event for
a manual change to the text in the text field itself... there is no overlap
between the two and that makes, in my opinion, for easier coding. I'm a
little surprised that this event model was not carried through to the Office
ComboBox.

By the way, thank you for bringing this to my attention... I really
appreciate it.

Rick


"Tim Zych" <tzych@NOSp@mE@RTHLINKDOTNET> wrote in message
news:(E-Mail Removed)...
>> The Change event of a ComboBox gets fired only when the text is manually
>> changed... not from selecting from the list.

>
> I don't think so Rick. If you create a sample form/cbo and try it out you
> should see. Type in a value, or select from the list in any way, and the
> change event is triggered. The help file has been updated, I believe, to
> include a lot more details about the control and the change/click events
> than prior versions documented.
>
> ----------------------------------------------------------
> From the help file in XL2003, Combobox control -> Events ->
> ------------------
> Change event:
> ------------------
> The Change event occurs when the setting of the Value property changes,
> regardless of whether the change results from execution of code or a user
> action in the interface.
> Note In some cases, the Click event may also occur when the Value property
> changes. However, using the Change event is the preferred technique for
> detecting a new value for a property.
> ----------------------------------------------------------
>
> Private Sub ComboBox1_Change()
> MsgBox "change"
> End Sub
>
> Private Sub UserForm_Initialize()
> With Me.ComboBox1
> .AddItem "a"
> .AddItem "b"
> .AddItem "c"
> End With
> End Sub
>
>
> Tim Zych
> SF, CA
>
>
> "Rick Rothstein (MVP - VB)" <(E-Mail Removed)> wrote in
> message news:(E-Mail Removed)...
>> The Change event of a ComboBox gets fired only when the text is manually
>> changed... not from selecting from the list. I suspect you have code in
>> your Change event which you think is doing something that actually is
>> happening automatically; hence, when you type into the text field,
>> whatever happens automatically takes place and then something in your
>> Change event code makes it happen again. I can't tell you any more than
>> that because you didn't post your code for us to look at.
>>
>> Rick
>>
>>
>> "Smurfette18" <(E-Mail Removed)> wrote in message
>> news:0f220c1d-ccef-4cb7-ae49-(E-Mail Removed)...
>>> Hello,
>>>
>>> I have combo box that allows users to select from a list or enter a
>>> value freeform. I also have a change event for this combo box.
>>> Everything works fine when the user selects from the list, but when he
>>> or she enters a value by hand, the change event sometimes fires twice
>>> for no apparent reason. For instance, if you select "0" from the
>>> list, it fires once, but if you type "0" directly in the box, it fires
>>> twice. I already tried disabling events before my code and re-
>>> enabling them after it runs, but that did not work. Any help would be
>>> appreciated.
>>>
>>> Thanks!

>>

>
>


 
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
How Capture Cell Value Before Change Event Fires? =?Utf-8?B?TVZQIFdhbm5hYmU=?= Microsoft Excel Programming 2 28th Jun 2007 09:16 PM
Problem with CommandBarComboBox Change Event (Event fires only once) M. Khalid Farooq Microsoft Outlook Interoperability 6 23rd Oct 2006 09:44 AM
Problem with CommandBarComboBox Change Event (Event fires only once) M. Khalid Farooq Microsoft Outlook Program Addins 1 19th Oct 2006 02:34 PM
No Afterupdate event fires in unbound Combo Lars Gustavsson Microsoft Access 1 11th Nov 2004 08:17 PM
comboBox TextChanged event fires twice because Items.Insert() fires the event too... Rob Hindman Microsoft Dot NET Framework Forms 2 25th Aug 2003 07:10 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:43 PM.