Stop the _Change event? Is there EnableEvents for Forms?

T

T_o_n_y

I would like to be able to temporarily disable one of the _Change events in
my form because I don't want it to fire during, for example, the initialize
sub. I've tried several things including using the .enabled=false, and
..locked=false, and even Application.EnableEvents = False, ...but the _Change
event still fired. Here is the specific sub I want to temporarily disable.
It's for a textbox called CurrentPBox that calls a very involved Draw routine.

Private Sub CurrentPBox_click()
If IsNumeric(CurrentPBox) And CurrentPBox <= CurrentPSpin.Max _
And CurrentPBox >= CurrentPSpin.Min Then
pCurrentP = CurrentPBox 'if its a valid value, store the value & spin
CurrentPSpin = CurrentPBox
DrawPetal pCurrentP, p, m, s, pCor
pBox = pCurrentP
Else
CurrentPBox = pCurrentP 'if its invalid, replace it with what had been there
End If
End Sub

Thanks!
-Tony
 
T

Tom Ogilvy

Set events to false. Then is the code you don't want to run

Private Sub CurrentPBox_click()
If application.EnableEvents = False then exit sub
If IsNumeric(CurrentPBox) And CurrentPBox <= CurrentPSpin.Max _
And CurrentPBox >= CurrentPSpin.Min Then
pCurrentP = CurrentPBox 'if its a valid value, store the value & spin
CurrentPSpin = CurrentPBox
DrawPetal pCurrentP, p, m, s, pCor
pBox = pCurrentP
Else
CurrentPBox = pCurrentP 'if its invalid, replace it with what had been
there
End If
End Sub

EnableEvents only works on events in the Excel object module. However, you
can check its status in this event.
 
B

Bob Phillips

I see that Tom has offered up a (quite novel) solution, but the way that I
do it is to maintain my own events Boolean, like so

Private fReEntry As Boolean

Private Sub CurrentPBox_click()
If Not fReEntry Then
fReEntry = True
If IsNumeric(CurrentPBox) And CurrentPBox <= CurrentPSpin.Max _
And CurrentPBox >= CurrentPSpin.Min Then
pCurrentP = CurrentPBox 'if its a valid value, _
store the value & spin
CurrentPSpin = CurrentPBox
DrawPetal pCurrentP, p, m, s, pCor
pBox = pCurrentP
Else
CurrentPBox = pCurrentP 'if its invalid, _
replace it with what had been there
End If
fReEntry = False
End If
End Sub


--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
T

T_o_n_y

Tom,

That's clever.

Thanks.
-Tony

Tom Ogilvy said:
Set events to false. Then is the code you don't want to run

Private Sub CurrentPBox_click()
If application.EnableEvents = False then exit sub
If IsNumeric(CurrentPBox) And CurrentPBox <= CurrentPSpin.Max _
And CurrentPBox >= CurrentPSpin.Min Then
pCurrentP = CurrentPBox 'if its a valid value, store the value & spin
CurrentPSpin = CurrentPBox
DrawPetal pCurrentP, p, m, s, pCor
pBox = pCurrentP
Else
CurrentPBox = pCurrentP 'if its invalid, replace it with what had been
there
End If
End Sub

EnableEvents only works on events in the Excel object module. However, you
can check its status in this event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top