Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA code running on it's own

Status
Not open for further replies.

RomeERome

Programmer
Nov 17, 2003
45
US
I have some VBA code that is behind two activex comboboxs, and I have some code behind four activex buttons. All my code works just fine, but at certain places in the code, other code runs in between this code. It's very frustrating, because they are firing when they're not being called.

I wanted them to fire only when they are called. I have tried to prevent this by creating a global public variable called jcDisabledEvents and declared it as Boolean. This is the way that my code is setup.

Code:
Public jcDisabledEvents As Boolean

The code below is placed in the subroutine that are misfiring.

Code:
If jcDisabledEvents = True Then Exit Sub

While debugging the VBA code, I figured out where the code is firing without being called, and I have entered the lines of code below in each of the subroutines where the misfiring is taking place.

Code:
jcDisabledEvents = True 'turn code off
code....
jcDisabledEvents = False 'turn code back on

After entering this code, it stops my code that is misfiring from working when it is called.

This is driving me nuts.

If anyone can help please do and fast!!!
 

hi,

In the VB Editor, add a WATCH for your boolean variable. Make it GLOBAL Context and choose the Watch Type to BREAK, whichever type you choose.

This ought to help you debug your problem.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
What you show is not really helpful. Show the code the is supposedly firing and the code at which is running when this other code "fires".

Bottom line, you are either calling it from the other code and not seeing it, or you called it earlier and control is finally getting back to the processor. The event was cached. The latter is fixed with a DoEvents placed in the proper location. Code just does not execute on its own.
 
Unless it's in the Twilight Zone. [wink]

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
OK, but besides Skynet, The Matrix, HAL... I stand by my assertion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top