View Single Post
  #2   Report Post  
Posted to microsoft.public.access.formscoding,microsoft.public.excel.programming,microsoft.public.word.vba.userforms
Bob Umlas Bob Umlas is offline
external usenet poster
 
Posts: 301
Default Force event code to NOT respond

In the event code, start the first line with:
Application.EnableEvents = False
and end with
Application.EnableEvents = True

Bob Umlas
Excel MVP

"Peter Danes" wrote in message
...
I have this problem in all three Office products which I regularly program,
Access, Excel and Word.

I write event handlers to respond to (for instance) a change event, but my
intention is to respond only to changes made by the user. The problem I
have
often encountered is that somewhere in code I have reason to change the
contents of a form control and that also fires the change event. The only
way I have found so far to deal with this is to set some sort of global
variable (or sometimes the .Tag property) and have the event code check
the
status of that global variable to determine whether it should in fact
respond to the change event, or just exit again immediately.

This works, but it's awkward to code and prone to logic bugs. Does anyone
know of a better way to deal with events that are triggered by code when I
want the event code to respond ONLY to activities by the user?

Pete

This e-mail address is fake to keep spammers and their auto-harvesters out
of my hair. If you need to get in touch personally, I am 'pdanes' and I
use
Yahoo mail. But please use the newsgroups whenever possible, so that all
may
benefit from the exchange of ideas.