Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Problem with execute command in mailmerge
Hi all,
I'm using word automation with Ms Office 2003. I used to have working sources for Ms Office 2000, but as of always, things evolve... I recreated my classes in visual c++ 6 based on the MSWORD.OLB file. Opening word is working again perfectly, opening the datasource as well. But when I set the destination for the mailmerge object to wdSendToPrinter as it always was and then perform an execute method, I get an exception that says 'word could not finish merging these documents or inserting this database' and nothing gets sent to the printer. However, If I set the destination to wdSendToNewDocument and execute, the new document is created. Anybody any idea how I could make it work with sendtoprinter, or what could be the cause of this error. Thanks in advance, J Roeland _ApplicationWord* objWord = new _ApplicationWord(); if (!objWord-CreateDispatch("Word.Application")) { AfxMessageBox("Couldn't get Word object."); return; } objWord-SetVisible(TRUE); //This shows the application. Documents docs(objWord-GetDocuments()); _Document testDoc; testDoc.AttachDispatch( docs.Open( COleVariant(document,VT_BSTR), //FileName covFalse, // Confirm Conversion. covFalse, // ReadOnly. covFalse, // AddToRecentFiles. covOptional, // PasswordDocument. covOptional, // PasswordTemplate. covFalse, // Revert. covOptional, // WritePasswordDocument. covOptional, // WritePasswordTemplate. covOptional, // Format. covOptional, // Encoding covOptional, // Visible covOptional, // OpenConflictDocument covOptional, // OpenAndRepair covOptional, // DocumentDirection covOptional // NoEncodingDialog ) ); MailMerge mergemail; mergemail = testDoc.GetMailMerge(); long values = mergemail.GetState(); if(values != 1)//wdMainAndDataSource { CString strConnection = "DSN=MS Access Databases;DBQ=C:\\ifastoVDB\\facstock2000.mdb;FIL= RedISAM;"; mergemail.OpenDataSource( "c:\\IfastoVDB \\facstock2000.mdb", covFalse, covFalse, covFalse, covTrue, covFalse, covOptional, covOptional, covOptional, covOptional, covOptional, COleVariant(strConnection), COleVariant("Select * from [USERQUERY_MailingKlanten]",VT_BSTR), USERQUERY_MailingKlanten",VT_BSTR), covOptional, //COleVariant("Select from [USERQUERY_MailingKlanten]",VT_BSTR) covFalse, covOptional ); values = mergemail.GetState(); } mergemail.SetDestination(1);//0=wdSendToNewDocument,1 =wdSendToPrinter,2=wdSendToEmail,3= wdSendToFax try { mergemail.Execute( covOptional); } catch (CException* exc) { AfxMessageBox(exc-ReportError()); } |
#2
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Problem with execute command in mailmerge
How about send to the new document and then use code to print that out.
-- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP "JurgenRoeland" wrote in message ... Hi all, I'm using word automation with Ms Office 2003. I used to have working sources for Ms Office 2000, but as of always, things evolve... I recreated my classes in visual c++ 6 based on the MSWORD.OLB file. Opening word is working again perfectly, opening the datasource as well. But when I set the destination for the mailmerge object to wdSendToPrinter as it always was and then perform an execute method, I get an exception that says 'word could not finish merging these documents or inserting this database' and nothing gets sent to the printer. However, If I set the destination to wdSendToNewDocument and execute, the new document is created. Anybody any idea how I could make it work with sendtoprinter, or what could be the cause of this error. Thanks in advance, J Roeland _ApplicationWord* objWord = new _ApplicationWord(); if (!objWord-CreateDispatch("Word.Application")) { AfxMessageBox("Couldn't get Word object."); return; } objWord-SetVisible(TRUE); //This shows the application. Documents docs(objWord-GetDocuments()); _Document testDoc; testDoc.AttachDispatch( docs.Open( COleVariant(document,VT_BSTR), //FileName covFalse, // Confirm Conversion. covFalse, // ReadOnly. covFalse, // AddToRecentFiles. covOptional, // PasswordDocument. covOptional, // PasswordTemplate. covFalse, // Revert. covOptional, // WritePasswordDocument. covOptional, // WritePasswordTemplate. covOptional, // Format. covOptional, // Encoding covOptional, // Visible covOptional, // OpenConflictDocument covOptional, // OpenAndRepair covOptional, // DocumentDirection covOptional // NoEncodingDialog ) ); MailMerge mergemail; mergemail = testDoc.GetMailMerge(); long values = mergemail.GetState(); if(values != 1)//wdMainAndDataSource { CString strConnection = "DSN=MS Access Databases;DBQ=C:\\ifastoVDB\\facstock2000.mdb;FIL= RedISAM;"; mergemail.OpenDataSource( "c:\\IfastoVDB \\facstock2000.mdb", covFalse, covFalse, covFalse, covTrue, covFalse, covOptional, covOptional, covOptional, covOptional, covOptional, COleVariant(strConnection), COleVariant("Select * from [USERQUERY_MailingKlanten]",VT_BSTR), USERQUERY_MailingKlanten",VT_BSTR), covOptional, //COleVariant("Select from [USERQUERY_MailingKlanten]",VT_BSTR) covFalse, covOptional ); values = mergemail.GetState(); } mergemail.SetDestination(1);//0=wdSendToNewDocument,1 =wdSendToPrinter,2=wdSendToEmail,3= wdSendToFax try { mergemail.Execute( covOptional); } catch (CException* exc) { AfxMessageBox(exc-ReportError()); } |
#3
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Problem with execute command in mailmerge
|
#4
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Problem with execute command in mailmerge
It will normally be the ActiveDocument.
-- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP "Candyman" wrote in message ... "Doug Robbins - Word MVP" wrote in news:OI#5wi# : How about send to the new document and then use code to print that out. Hmm good idea, I hadn't thought of that yet. Any idea how you can recover the new created document from the documents collection ? Jurgen |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Word 2003 Mailmerge problem - works in Word 2000 | Mailmerge | |||
XML Word Mailmerge problem | Mailmerge | |||
Mailmerge Access record duplication problem..Deadline Help ASAP Pl | Mailmerge | |||
Mailmerge from EXCEL, custom format problem | Mailmerge | |||
Problem with mailmerge from with a rtf datasource, from access vba | Mailmerge |