Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word throws exception after MailMerge
Message
From
29/10/2003 10:09:49
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Word throws exception after MailMerge
Miscellaneous
Thread ID:
00844080
Message ID:
00844080
Views:
36
Hey all,

I have the following code:
DO CreateDSN IN odbc.prg WITH "TEMPVFP", pcDatabase, "DBC"
lcConnectionString = [DSN=TEMPVFP;SourceDB=] + pcDatabase + [;SourceType=DBC]
lcSQL = [SELECT * FROM ] + pcTable
oWord = CREATEOBJECT("Word.Application")
oDocument = oWord.Documents.Open(pcDocFile)
WITH oDocument.MailMerge
    .OpenDataSource(,,,.T.,,,,,,,,lcConnectionString,lcSQL,,,wdMergeSubTypeWord2000)
    .Destination = wdSendToPrinter
    .Execute()
ENDWITH
oWord.Visible = .T.
oDocument.Close("0")    &&   <----- ERROR THROWN HERE
oWord.Quit("0")         
oWord = .NULL.
RELEASE oWord
Basically, I am creating an ODBC DSN, hooking a Word MailMerge document to it, executing the merge straight to printer, and then wanting to close out.

Everything works great except the closing out. On the line labeled (trying to close the document), I get an OLE error "The server threw an exception".

I made Word visible to try to see if I could see anything weird. After the Close() errors out, Word is all hung up. You can see the menu and title, but the rest of the Word screen is frozen.

If I manually go to Word when I make it visible and try to close the document (before throwing the error), I get a "Word has encountered an uxpected error" message, and Word bombs out, so my automation calls do not appear to be the problem.

Finally, if I try to do a straight Quit, it also errors out and/or hangs. I need to figure out why the original doc won't close.

I could rig a way to just kill all WINWORD processes, but I am afraid of killing machines by doing that, wasting memory until users are forced to reboot. What is going on here? Do I need to close my data connection somehow? If so, how is that done? Word works fine for everything else, including other merges that use DAT files. I can't use DAT files because my field list exceeds 255 characters, and if I cahnge my field names I will have to change a TON of other reports and imaging code that uses the existing data structure.

Also, I can do the entire merge process just in Word through the merge wizard, same data and same doc, and it all works without hanging. It's got to be something with my OpenDataSource where Word is getting confused at me trying to dynamically set up its merge data. If there a better way to dynamically assign data to Word's merge? Please help!

JoeK
Next
Reply
Map
View

Click here to load this message in the networking platform