View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default toggle button or worksheet_activate causing form to open twice

It exits when bBlockEvents is True.
Otherwise, events are not being blocked - so the next step in the event is
to set it to True so any subsequent event will be blocked. It then performs
an action that triggers an event, but the event code performs the test and
exits (is blocked). At the end of such actions, it sets it back to False so
the next event triggered externally will be handled.

just an added comment,

My declaration should have been

Public bBlockEvents as boolean

as posted it is a variant (just a typo)

It doesn't make any real difference, however, since being empty or false are
equivalent in the if test.
--
Regards,
Tom Ogilvy

"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?