Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / December 2005

Tip: Looking for answers? Try searching our database.

Problem with execute command in mailmerge

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JurgenRoeland - 03 Dec 2005 08:47 GMT
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());
     }
Doug Robbins - Word MVP - 03 Dec 2005 09:05 GMT
How about send to the new document and then use code to print that out.

Signature

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

> Hi all,
>
[quoted text clipped - 93 lines]
>   AfxMessageBox(exc->ReportError());
>   }
Candyman - 06 Dec 2005 16:12 GMT
"Doug Robbins - Word MVP" <dkr@REMOVETHISmvps.org> wrote in news:OI#5wi#
9FHA.3560@TK2MSFTNGP12.phx.gbl:

> 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
Doug Robbins - Word MVP - 06 Dec 2005 18:20 GMT
It will normally be the ActiveDocument.

Signature

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

> "Doug Robbins - Word MVP" <dkr@REMOVETHISmvps.org> wrote in news:OI#5wi#
> 9FHA.3560@TK2MSFTNGP12.phx.gbl:
[quoted text clipped - 6 lines]
>
> Jurgen
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.