DocumentChange event: microsoft bug?

G

gandalf

FOR WORD XP

Has anyone noticed anything strange in the DocumentChange event?

I have an addin which is catching this event, and it is fired too
often: it is supposed to fire when a new doc is created, an existing
one ic closed or another document gets focus, but in my case it is
fired also when i update fields in table or headers, lor when i add
tables, etc.

Thanks
 
T

Tom Winter

You might want to check out the other events then. DocumentOpen,
NewDocument and WindowActivate might do what you need.
 
G

gandalf

Tom Winter said:
You might want to check out the other events then. DocumentOpen,
NewDocument and WindowActivate might do what you need.

No we cannot, unfortunately.
In addition we have some macros from another company to integrate
tehir product with Word, and those macros are catching the
DocumentChange event, and they are firedd when not needed. since this
macros requires a connection to the DB, each time I update a doc
containing 30 fields, 30 DB connections are made one after the other,
slowing down Word to death
 
T

Tom Winter

gandalf said:
No we cannot, unfortunately.
In addition we have some macros from another company to integrate
tehir product with Word, and those macros are catching the
DocumentChange event, and they are firedd when not needed. since this
macros requires a connection to the DB, each time I update a doc
containing 30 fields, 30 DB connections are made one after the other,
slowing down Word to death

I assume you are not able to change the macros? If that's the case, there's
not much more I can help you with. I myself have never used the
DocumentChange event, so I'm not familiar with any problems related to it.
 
J

Jean-Guy Marcil

gandalf was telling us:
gandalf nous racontait que :
No we cannot, unfortunately.
In addition we have some macros from another company to integrate
tehir product with Word, and those macros are catching the
DocumentChange event, and they are firedd when not needed. since this
macros requires a connection to the DB, each time I update a doc
containing 30 fields, 30 DB connections are made one after the other,
slowing down Word to death

See Pete Benett's solution for something like this:
http://tinyurl.com/6rfuf

Also, according to
http://msdn.microsoft.com/library/d...ry/en-us/off2000/html/woevtdocumentchange.asp
the document change event fires only in certain circumstances. If you get a
different behaviour, then it may be that the third party add-in you are
using was badly designed and doing things in the background that are not
visible but that meet with the criteria for firing a DocumentChange event.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
G

gandalf

Also, according to
http://msdn.microsoft.com/library/d...ry/en-us/off2000/html/woevtdocumentchange.asp
the document change event fires only in certain circumstances. If you get a
different behaviour, then it may be that the third party add-in you are
using was badly designed and doing things in the background that are not
visible but that meet with the criteria for firing a DocumentChange event.

Forgot one thing: I don't have this problem with Word97, but only with
WordXP...
It must be a bug: why the DocumentChange event should fire when i
update the fields of a document?
 
J

Jean-Guy Marcil

gandalf was telling us:
gandalf nous racontait que :
Forgot one thing: I don't have this problem with Word97, but only with
WordXP...
It must be a bug: why the DocumentChange event should fire when i
update the fields of a document?

I tested the DocumentChange event on Word XP and Word 2003.

It behaved exactly as it was supposed to. I inserted tables, deleted them,
opened/closed headers with/without fields, updated fields in headers/tables,
mailmerged, etc.
No problem.

This is why I suggested that either there is something in your code that you
have not considered that fires the event, or the third-party add-in is doing
stuff you do not know about (do you have access to the code?) or your
template is corrupt.

OTHO, I have not tested it with a DB connection.
If there is a bug, can you narrow it down and provide a step by step
procedure so that others can reproduce it?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
P

Peter_A_M (NL)

For myself I'd try to work with a public variable as a "flag"
(e.g. declaration in module: Public FlagDBConnected as Boolean).
You could set this variable to True once your DB is connected so that your
code needs not try to do this anymore.
Remains the problem to decide when (& where & how) to set the variable to
False again.

Peter
 
M

Michael Schmidt

Jean-Guy Marcil said:
gandalf was telling us:
gandalf nous racontait que :


I tested the DocumentChange event on Word XP and Word 2003.

It behaved exactly as it was supposed to. I inserted tables, deleted them,
opened/closed headers with/without fields, updated fields in headers/tables,
mailmerged, etc.
No problem.

This is why I suggested that either there is something in your code that you
have not considered that fires the event, or the third-party add-in is doing
stuff you do not know about (do you have access to the code?) or your
template is corrupt.

OTHO, I have not tested it with a DB connection.
If there is a bug, can you narrow it down and provide a step by step
procedure so that others can reproduce it?


Maybe the easiest thing is to include a workaround into the
Document_Change procedure:

Declare the sub as static or declare a variable on class level in
which you enter the Name of the document that caused the call of the
Document_Change sub. If it is the same as the time before, ignore the
event:

Public WithEvents MSWord As Application

Private Static Sub MSWord_DocumentChange()

Dim LastDoc As String

If ActiveDocument.Name = LastDoc Then
Exit Sub
Else
LastDoc = ActiveDocument.Name
End If

' Body of proc ...

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top