Home All Groups Group Topic Archive Search About
Author
17 Oct 2005 8:45 PM
HotRod
Can anyone remind me how to stop an event from firing? I mean once the event
fires the first line of code is "Stop events from firing" and then I can
turn it back on at the end of that event???

Author
17 Oct 2005 9:06 PM
MikeD
"HotRod" <NOSPAM@youremail.com> wrote in message
news:%238MNyu10FHA.2076@TK2MSFTNGP14.phx.gbl...
> Can anyone remind me how to stop an event from firing? I mean once the
> event fires the first line of code is "Stop events from firing" and then I
> can turn it back on at the end of that event???

Normally, you can't stop the event from firing.  I say "normally" because
there are controls/components with a property (for example) that can be set
to ignore certain events (for example, not raise them).  However, this would
have to be functionality specifically written into the component.

Other than that possibility, the only thing you can do is have a
module-level variable to which you assign a value and then check for that
value in the event procedure itself, and if, appropriate, exit the event
procedure.

--
Mike
Microsoft MVP Visual Basic
Author
17 Oct 2005 10:04 PM
Tom Esh
On Mon, 17 Oct 2005 16:45:15 -0400, "HotRod" <NOSPAM@youremail.com>
wrote:

>Can anyone remind me how to stop an event from firing? I mean once the event
>fires the first line of code is "Stop events from firing" and then I can
>turn it back on at the end of that event???

If you just want to prevent re-entry in the current proceedure you can
use a static var as a flag.

Private Sub SomeSub()
    Static bBusy As Boolean

    If Not bBusy Then
        bBusy = True

        '...do whatever ...

        bBusy = False
    End If
End Sub


-Tom
MVP - Visual Basic
(please post replies to the newsgroup)
Author
18 Oct 2005 8:45 AM
Mike Williams
"HotRod" <NOSPAM@youremail.com> wrote in message
news:%238MNyu10FHA.2076@TK2MSFTNGP14.phx.gbl...

> Can anyone remind me how to stop an event from firing? I mean once
> the event fires the first line of code is "Stop events from firing" and
> then
> I can turn it back on at the end of that event???

I'm not sure what you mean. Do you by any chance mean "how can I stop
further button click events from firing while my code processes the last
click", ort is it something more general that that?

Mike
Author
18 Oct 2005 2:08 PM
HotRod
Mike your right, I want the Event to complete before trying to fire the
event again.
Author
18 Oct 2005 2:41 PM
Mike Williams
"HotRod" <NOSPAM@youremail.com> wrote in message
news:%236GOCD$0FHA.3780@TK2MSFTNGP12.phx.gbl...

> Mike your right, I want the Event to complete before trying
> to fire the event again.

If it is a Command Button Click event then just place the line
"Command1.Enabled = False" at the start of the event code and the lines
"Doevents" followed by "Command1.Enabled = False" at the end of the event
code (other objects can be dealt with in a similar way). If instead it is a
general thing (and the event code is in a Form, for example) then maintain a
Form level Boolean (Working, for example) and put something like the
following at the start of the event code:

If Working = True Then
  Exit Sub
Else
  Working = True
End If
'
your event code here
'
DoEvents
Working = False
End Sub

If that doesn't help you then I've misunderstood your problem, so post
again.

Mike
Author
18 Oct 2005 3:03 PM
Someone
Here is how I do it with a Timer:

Dim bTimer1Busy As Boolean

Private Sub Timer1_Timer()

    If bTimer1Busy Then
        Exit Sub
    End If
    bTimer1Busy = True

    ' Your code here

    bTimer1Busy = False
End Sub


Show quoteHide quote
"HotRod" <NOSPAM@youremail.com> wrote in message
news:%236GOCD$0FHA.3780@TK2MSFTNGP12.phx.gbl...
> Mike your right, I want the Event to complete before trying to fire the
> event again.
>