Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
JurgenRoeland
 
Posts: n/a
Default 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   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP
 
Posts: n/a
Default 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   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Candyman
 
Posts: n/a
Default Problem with execute command in mailmerge

"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
  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP
 
Posts: n/a
Default 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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 2003 Mailmerge problem - works in Word 2000 Rick Robinson Mailmerge 2 April 28th 05 10:16 AM
XML Word Mailmerge problem Enq Mailmerge 1 March 22nd 05 12:48 AM
Mailmerge Access record duplication problem..Deadline Help ASAP Pl Paul Mailmerge 1 February 14th 05 11:12 PM
Mailmerge from EXCEL, custom format problem TonyB Mailmerge 1 December 1st 04 04:41 PM
Problem with mailmerge from with a rtf datasource, from access vba VincE Mailmerge 1 December 1st 04 02:30 PM


All times are GMT +1. The time now is 01:49 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"