BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Word event not firing consistantly in MailMerge

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
-Jas
Guest





PostPosted: Fri Aug 05, 2005 1:40 am    Post subject: Word event not firing consistantly in MailMerge Reply with quote




Delphi 7, XP pro, Word 2003

I have found that the events during Word MailMerge don't always fire and I'm hoping someone here can tell me why, and what to do about it.

When doing a mailmerge from Delphi I have created routines for the two events, before and after record merge.
They both fire all of the time when I do a merge of about 40 records in a single pass as follows:
I dropped the Delphi component for WordApplication onto the form and that is what I'm referncing below.

WordApp1.Documents.Open(DocFilename, EmptyParam, ....etc)
WordApp1.ActiveDocument.MailMerge.OpenDataSource(DataFilename, EmptyParam, ....etc)
WordApp1.ActiveDocument.MailMerge.Destination := wdSendToPrinter
WordApp1.ActiveDocument.MailMerge.Execute(bTrue);
WordApp1.ActiveDocument.Close(DoNotSaveChanges,EmptyParam,EmptyParam);

However, if I do a calling the above 20 times for a single document, the event MailMergeAfterRecordMerge at random, skips firing.

Somebody was kind enough to point out that events in general are queued up and will fire earlier or later depending on what's already in the queue. So I put in about a dozen application.processmessages between each of the above steps and it works without a skip.
The downside of course is that the process really runs slowly.

So I tried something else (totally my own stupid idea).
In the event code I increment a counter. If the event doesn't fire, then my counter doesn't get incremented.
I thought the problem was in closing before the event could fire, so I put a loop right after the call to Execute
and tested my counter until it had incremented.

i := iCounter
x := 0;
WordApp1.ActiveDocument.MailMerge.Execute(bTrue);
while i = iCounter do
begin
application.processmessages;
inc(x);
end;
WordApp1.ActiveDocument.Close(DoNotSaveChanges,EmptyParam,EmptyParam);

What I found suprised me: if the event had not fired by the time it returned from the Execute call, it wasn't going to, no matter how long I waited.

So my question, can I force the event to fire? or failing that how can I wait the minimum time so that it does fire?
Any insight that might help here would be greatly appreciated.
Thanks,
-Jas
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.