J
JurgenRoeland
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());
}
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());
}