PC Review


Reply
Thread Tools Rate Thread

Disabling events within an event handler

 
 
feltra
Guest
Posts: n/a
 
      7th Apr 2007
Hi,

I have 2 comboboxes created from the Control Toolbox. I want to set
the text of one combobox when the other is clicked. Here's a sample
code for the Change event for them. (line numbers are given for easy
reference - they dont exist in the code)

1 private sub Combobox1_Change()
2 do stuff
3 Combobox2.Text = "something"
4 end sub
5
6 private sub Combobox2_change()
7 do stuff
8 Combobox1.Text = "the other thing"
9 end sub

In the above, when Combobox1_Change() is executing, I do not want it
to go to Combobox2_change()... This is happening. I then replaced
line 3 with the following:
Application.EnableEvents = False
Combobox2.Text = "something"
Application.EnableEvents = True

Well, the problem continues. I tired other things like setting
Combobox1.Application.Events flag. Same result. It just does not
seem to ignore the Change event for Combobox2.

How do I make this happen?

Thanks a lot for any pointers & Best Regards,
-feltra

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      7th Apr 2007
One way to do it is to have a module or form level variable.


Private bBox1Changing As Boolean

Private Sub Combobox1_Change()
bBox1Changing = True
ComboBox2.Text = "something"
bBox1Changing = False
End Sub

Private Sub Combobox2_change()
If bBox1Changing Then Exit Sub
ComboBox1.Text = "the other thing"
End Sub



--
Hope that helps.

Vergel Adriano


"feltra" wrote:

> Hi,
>
> I have 2 comboboxes created from the Control Toolbox. I want to set
> the text of one combobox when the other is clicked. Here's a sample
> code for the Change event for them. (line numbers are given for easy
> reference - they dont exist in the code)
>
> 1 private sub Combobox1_Change()
> 2 do stuff
> 3 Combobox2.Text = "something"
> 4 end sub
> 5
> 6 private sub Combobox2_change()
> 7 do stuff
> 8 Combobox1.Text = "the other thing"
> 9 end sub
>
> In the above, when Combobox1_Change() is executing, I do not want it
> to go to Combobox2_change()... This is happening. I then replaced
> line 3 with the following:
> Application.EnableEvents = False
> Combobox2.Text = "something"
> Application.EnableEvents = True
>
> Well, the problem continues. I tired other things like setting
> Combobox1.Application.Events flag. Same result. It just does not
> seem to ignore the Change event for Combobox2.
>
> How do I make this happen?
>
> Thanks a lot for any pointers & Best Regards,
> -feltra
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      7th Apr 2007
This isn't an event to excel. So you have to take care of it yourself.

Option Explicit
Public BlkProc As Boolean
private sub Combobox1_Change()
if blkproc = true then exit sub
do stuff
blkproc = true
Combobox2.Text = "something"
blkproc = false
end sub

private sub Combobox2_change()
if blkproc = true then exit sub
do stuff
blkproc = true
Combobox1.Text = "the other thing"
blkproc = false
end sub

feltra wrote:
>
> Hi,
>
> I have 2 comboboxes created from the Control Toolbox. I want to set
> the text of one combobox when the other is clicked. Here's a sample
> code for the Change event for them. (line numbers are given for easy
> reference - they dont exist in the code)
>
> 1 private sub Combobox1_Change()
> 2 do stuff
> 3 Combobox2.Text = "something"
> 4 end sub
> 5
> 6 private sub Combobox2_change()
> 7 do stuff
> 8 Combobox1.Text = "the other thing"
> 9 end sub
>
> In the above, when Combobox1_Change() is executing, I do not want it
> to go to Combobox2_change()... This is happening. I then replaced
> line 3 with the following:
> Application.EnableEvents = False
> Combobox2.Text = "something"
> Application.EnableEvents = True
>
> Well, the problem continues. I tired other things like setting
> Combobox1.Application.Events flag. Same result. It just does not
> seem to ignore the Change event for Combobox2.
>
> How do I make this happen?
>
> Thanks a lot for any pointers & Best Regards,
> -feltra


--

Dave Peterson
 
Reply With Quote
 
feltra
Guest
Posts: n/a
 
      8th Apr 2007
Hi Dave & Vergel,

Thanks a lot for the valuable inputs... Before your replies came in,
I kept searching the archives and found an older post with similar
solution (in the same group). Only I had to change the public "Dim"
to "Public" - and it works like a charm...

Sergei, I will try out declaring it as "Private" to outside the
procedure also... I am still new to Excel VBA, (coming from a Unix/C
bkground).

Thanks a million & Best Regards,
-feltra

Dave Peterson wrote:
> This isn't an event to excel. So you have to take care of it yourself.
>
> Option Explicit
> Public BlkProc As Boolean
> private sub Combobox1_Change()
> if blkproc = true then exit sub
> do stuff
> blkproc = true
> Combobox2.Text = "something"
> blkproc = false
> end sub
>
> private sub Combobox2_change()
> if blkproc = true then exit sub
> do stuff
> blkproc = true
> Combobox1.Text = "the other thing"
> blkproc = false
> end sub
>
> feltra wrote:
> >
> > Hi,
> >
> > I have 2 comboboxes created from the Control Toolbox. I want to set
> > the text of one combobox when the other is clicked. Here's a sample
> > code for the Change event for them. (line numbers are given for easy
> > reference - they dont exist in the code)
> >
> > 1 private sub Combobox1_Change()
> > 2 do stuff
> > 3 Combobox2.Text = "something"
> > 4 end sub
> > 5
> > 6 private sub Combobox2_change()
> > 7 do stuff
> > 8 Combobox1.Text = "the other thing"
> > 9 end sub
> >
> > In the above, when Combobox1_Change() is executing, I do not want it
> > to go to Combobox2_change()... This is happening. I then replaced
> > line 3 with the following:
> > Application.EnableEvents = False
> > Combobox2.Text = "something"
> > Application.EnableEvents = True
> >
> > Well, the problem continues. I tired other things like setting
> > Combobox1.Application.Events flag. Same result. It just does not
> > seem to ignore the Change event for Combobox2.
> >
> > How do I make this happen?
> >
> > Thanks a lot for any pointers & Best Regards,
> > -feltra

>
> --
>
> Dave Peterson


 
Reply With Quote
 
feltra
Guest
Posts: n/a
 
      8th Apr 2007
Hi Vergel,

Sorry about using the wrong name (inside my earlier post).. I was
replying to another person (on another group) and somehow mixed up the
names...

Thanks & Regards,
-feltra

On Apr 8, 9:01 am, "feltra" <fel...@gmail.com> wrote:
> Hi Dave & Vergel,
>
> Thanks a lot for the valuable inputs... Before your replies came in,
> I kept searching the archives and found an older post with similar
> solution (in the same group). Only I had to change the public "Dim"
> to "Public" - and it works like a charm...
>
> Sergei, I will try out declaring it as "Private" to outside the
> procedure also... I am still new to Excel VBA, (coming from a Unix/C
> bkground).
>
> Thanks a million & Best Regards,
> -feltra
>
> Dave Peterson wrote:
> > This isn't an event to excel. So you have to take care of it yourself.

>
> > Option Explicit
> > Public BlkProc As Boolean
> > private sub Combobox1_Change()
> > if blkproc = true then exit sub
> > do stuff
> > blkproc = true
> > Combobox2.Text = "something"
> > blkproc = false
> > end sub

>
> > private sub Combobox2_change()
> > if blkproc = true then exit sub
> > do stuff
> > blkproc = true
> > Combobox1.Text = "the other thing"
> > blkproc = false
> > end sub

>
> > feltra wrote:

>
> > > Hi,

>
> > > I have 2 comboboxes created from the Control Toolbox. I want to set
> > > the text of one combobox when the other is clicked. Here's a sample
> > > code for the Change event for them. (line numbers are given for easy
> > > reference - they dont exist in the code)

>
> > > 1 private sub Combobox1_Change()
> > > 2 do stuff
> > > 3 Combobox2.Text = "something"
> > > 4 end sub
> > > 5
> > > 6 private sub Combobox2_change()
> > > 7 do stuff
> > > 8 Combobox1.Text = "the other thing"
> > > 9 end sub

>
> > > In the above, when Combobox1_Change() is executing, I do not want it
> > > to go to Combobox2_change()... This is happening. I then replaced
> > > line 3 with the following:
> > > Application.EnableEvents = False
> > > Combobox2.Text = "something"
> > > Application.EnableEvents = True

>
> > > Well, the problem continues. I tired other things like setting
> > > Combobox1.Application.Events flag. Same result. It just does not
> > > seem to ignore the Change event for Combobox2.

>
> > > How do I make this happen?

>
> > > Thanks a lot for any pointers & Best Regards,
> > > -feltra

>
> > --

>
> > Dave Peterson



 
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
Help with Event handler, withevents, raise events Ty Microsoft VB .NET 14 26th May 2009 10:30 AM
Help with Event handler, withevents, raise events Ty Microsoft VB .NET 0 25th May 2009 09:51 PM
Disabling Text Box Events on Form OnClose Event =?Utf-8?B?TmVpbGwgTS4gUGlua25leQ==?= Microsoft Access Forms 2 10th Nov 2004 07:33 PM
Managing the order of multiple Events link to a single Event Handler =?Utf-8?B?U3lsdmFpbg==?= Microsoft C# .NET 0 22nd Apr 2004 03:21 PM
Behavior of events when one event handler triggers an exception gs_sarge@yahoo.com Microsoft Dot NET Framework 1 30th Jan 2004 08:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:12 AM.