ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Disable Form Events From Being Triggered (https://www.excelbanter.com/excel-programming/342849-disable-form-events-being-triggered.html)

jgeniti

Disable Form Events From Being Triggered
 
Hello Group,

I have read many of the postings regarding the fact that you can't
disable form events. I have even created a Boolean called DisableEvent
that I use to escape from the offending event code. My issue that I'm
having is that I have 2 comboboxes and when I change the value of Box 1
(From A to B) it needs to clear the value of Box 2. When the Box 2
change event gets triggered the value of the box goes back to the
original value (from B back to A) regardless of the fact that I am
exiting the procedure before the code is executed.
Any ideas?

Here's the psuedocode of what's happening.

Box1 value is changed from A to B

Box1_OnChange
DisableEvent = True
Change Box 2 value to "" <This will trigger the Box2 Change Event
DisableEvent = False
....
....

Box2_OnChange <This is when the value goes back to A
If DisableEvent = True then Exit Sub
.....
.....


Tom Ogilvy

Disable Form Events From Being Triggered
 
Instead of using the change event, try using the click event.

--
Regards,
Tom Ogilvy


"JGeniti" wrote in message
ups.com...
Hello Group,

I have read many of the postings regarding the fact that you can't
disable form events. I have even created a Boolean called DisableEvent
that I use to escape from the offending event code. My issue that I'm
having is that I have 2 comboboxes and when I change the value of Box 1
(From A to B) it needs to clear the value of Box 2. When the Box 2
change event gets triggered the value of the box goes back to the
original value (from B back to A) regardless of the fact that I am
exiting the procedure before the code is executed.
Any ideas?

Here's the psuedocode of what's happening.

Box1 value is changed from A to B

Box1_OnChange
DisableEvent = True
Change Box 2 value to "" <This will trigger the Box2 Change Event
DisableEvent = False
....
....

Box2_OnChange <This is when the value goes back to A
If DisableEvent = True then Exit Sub
.....
.....




Bob Phillips[_6_]

Disable Form Events From Being Triggered
 
Show us the real code.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"JGeniti" wrote in message
ups.com...
Hello Group,

I have read many of the postings regarding the fact that you can't
disable form events. I have even created a Boolean called DisableEvent
that I use to escape from the offending event code. My issue that I'm
having is that I have 2 comboboxes and when I change the value of Box 1
(From A to B) it needs to clear the value of Box 2. When the Box 2
change event gets triggered the value of the box goes back to the
original value (from B back to A) regardless of the fact that I am
exiting the procedure before the code is executed.
Any ideas?

Here's the psuedocode of what's happening.

Box1 value is changed from A to B

Box1_OnChange
DisableEvent = True
Change Box 2 value to "" <This will trigger the Box2 Change Event
DisableEvent = False
....
....

Box2_OnChange <This is when the value goes back to A
If DisableEvent = True then Exit Sub
.....
.....




jgeniti

Disable Form Events From Being Triggered
 
-Tom
I only want to trigger the code if the user changes the value. Won't
the OnClick event cause the code to be triggered anytime someone clicks
into the combobox?

-Bob
Here is the code. The PackageType combobox is Box1 from my above
example. I still left out most of the code for the PackageComponent
combobox because there is almost 200 lines of code and the value of
PackageType gets changed back to the original value the instant that
OnChange event gets called for the PackageComponent.

Hopefully this will help. I just can't figure out why calling an
OnChange event from within another Onchange would cause the original
value to repopulate.

Thanks.
James

Private Sub PackageType_Change()

DisableEvent = True
PackageComponent.Value = ""
DisableEvent = False
PackageComponent.RowSource = ""
PackageComponent.Visible = False
PackageComponentLabel.Visible = False

End Sub


Private Sub PackageComponent_Change()

If DisableEvent = True Then Exit Sub
DeletePackageFormControls

.....
.....
....


Tom Ogilvy

Disable Form Events From Being Triggered
 
Click fires when an item is selected or if the user types in an item in the
list or if you did the equivalent with code. Clearing the combobox did not
fire the click event for me.

Private Sub CommandButton1_Click()
ComboBox1.ListIndex = -1
End Sub

Private Sub CommandButton2_Click()
ComboBox1.Value = ""
End Sub

these did not fire the click event for me.

--
Regards,
Tom Ogilvy


"JGeniti" wrote in message
ups.com...
-Tom
I only want to trigger the code if the user changes the value. Won't
the OnClick event cause the code to be triggered anytime someone clicks
into the combobox?

-Bob
Here is the code. The PackageType combobox is Box1 from my above
example. I still left out most of the code for the PackageComponent
combobox because there is almost 200 lines of code and the value of
PackageType gets changed back to the original value the instant that
OnChange event gets called for the PackageComponent.

Hopefully this will help. I just can't figure out why calling an
OnChange event from within another Onchange would cause the original
value to repopulate.

Thanks.
James

Private Sub PackageType_Change()

DisableEvent = True
PackageComponent.Value = ""
DisableEvent = False
PackageComponent.RowSource = ""
PackageComponent.Visible = False
PackageComponentLabel.Visible = False

End Sub


Private Sub PackageComponent_Change()

If DisableEvent = True Then Exit Sub
DeletePackageFormControls

....
....
...





All times are GMT +1. The time now is 12:05 PM.

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