View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default TOGGLE BUTTON on userform problem

Hi David,

Without any idea of what your sheet loop does I can only guess something
triggers the ToggleButton1_Click to fire a second time (resetting toggle
buttons would do that). Which would also suggest your entire loop also gets
repeated.

One way to prevent code within the event running, without disabling events,
is to set a module or global level flag, eg

Dim bExit as boolean
Private Sub ToggleButton1_Click()
if bExit then
Exit Sub
End if
bExit = true
On error goto errH:
For each sh in WorkSheets
<do something
k = k & something & vbcrlf
Next
MsgBox k
errH:
bExit = false
End Sub

Regards,
Peter T

"davidm" wrote in
message ...

As one of many subroutines in my project, there is a simple event
handler which triggers off a messagebox at the end of a loop.
Structurally, the code looks like:

Private Sub ToggleButton1_Click()
For each sh in WorkSheets
<do something
k = k & something & vbcrlf
Next
MsgBox k
End Sub

Now, for some strange reason, when the ToggleButton is clicked, the
MsgBox comes up *twice* each time. This is irritating, to say the least
and in my attempts to stop the nuisance I have tried the event variants
* Private Sub ToggleButton1_Change* and * Private Sub
ToggleButton1_Enter*-to no avail. While the Change event acts the same
way as the Click event (and shares the double movement problem), the
Enter event fires the MsgBox only once as desired but does not permit
repeat successive runs of the code.


For what it is worth, let me also remark that, when the code is
transplanted to a fresh userform and tested in its new enviroment, the
above problem disappears: the MsgBox springs up once and no more.


If anyone has the disgnostic eye for this problem, I welcome him
with thanks.

David.


--
davidm
------------------------------------------------------------------------
davidm's Profile:

http://www.excelforum.com/member.php...o&userid=20645
View this thread: http://www.excelforum.com/showthread...hreadid=487645