View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default toggle button or worksheet_activate causing form to open twice

To maybe say the same thing as Tom, but in a different manner ...

The routine exits when bBlockEvents is true.
It continues if bBlockEvents is false, but immediately sets it to True so
that if the event gets triggered recursively, it will immediately exit.
At the end, it resets bBlockEvents to False so that any new event triggering
will not immediately exit.

--

HTH

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


"Nicole B" wrote in message
...
I'm confused. I thought that the sub was exiting when bblockevents=false,

as
below (noted with asterisk). Otherwise, why wouldn't the sub end before

the
msgbox?

Public bBlockEvents

Private Sub ToggleButton1_Click()
If bBlockEvents Then Exit Sub
bBlockEvents = True
MsgBox ToggleButton1.Value
With ToggleButton1
.Caption = "Protect Sheets"
.Value = False
End With

* bBlockEvents = False
End Sub


"Bob Phillips" wrote:

This is because bBlockEvents is a boolean (True/False) variable, and

this is
the same as saying

If bBlockEvents = True Then Exit Sub

--

HTH

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


"Nicole B" wrote in message
...
I was wondering... how does your statement:
If bBlockEvents Then Exit Sub
work? is VB assuming some kind of value?