T
tgul
Hi,
I've been all over trying to apply answers to Word (2000) mail merge related
posts w/ regard to my issue but, to no avail.
My mail merge code used to work w/ Word 2000 and 2002 on NT 4.0 sp6 before
upgrading to Word 2002 sp3 on XP. Now running the code produces a an
exception w/ the following; "This method or property is not available because
the document is not a mail merge main document". The original code had a
dependency upon msword9.olb. I've removed the old dependency and generated
the wrapper classes for MS Word 2003 (msword.olb) and rebuilt. The word
template below has a datasource of a sqlserver table populated by the stored
proc called in the code. All fields match between table and .dot. Stepping
into the code at mailMergeMSWord.Execute, the exception is generated in MFC
code at oledisp2.cpp OleDispatchDriver::InvokeHelperV when a call to
m_lpDispatch->Invoke is made.
Your help would be very much appreciated. Let me know if I can supply more
info.
Regards,
tgul
My VC++ 6.0 code:
BOOL CMyClass : : PrintLetters()
{
CWaitCursor wait;
CString strSQL, strMessage;
_Application appMSWord
try
{
COleVariant vtOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR),
vtFalse((short)FALSE);
appMSWord.CreateDispatch( "Word.Application" );
CString strUserTemplatesPath =
((Options)appMSWord.GetOptions()).GetDefaultFilePath( 15 );
Documents docsMSWord = appMSWord.GetDocuments();
_Document docTemplateMSWord;
MailMerge mailMergeMSWord;
// Generate the letters
strSQL = "{CALL GenerateLetters (" +
pPropertySheet->GetCPIString() + ", '" +
pPropertySheet->GetDDstDayofMonth() + "', '" +
pPropertySheet->GetSelectedMonthYear() + "', '" +
pPropertySheet->GetIncreaseStartDate() + "', '" +
pPropertySheet->GetIncreaseEndDate() + "')}";
CLettersSet rsLetters( GetDb() );
if ( !GetDb()->OpenRecordset( &rsLetters, FALSE,
CRecordset::forwardOnly,
strSQL,
CRecordset::readOnly |
CRecordset::executeDirect ) )
{
appMSWord.ReleaseDispatch();
return FALSE;
}
if ( rsLetters.m_RowCount > 0 )
{
docTemplateMSWord =
docsMSWord.Open( COleVariant( strUserTemplatesPath + "\\generate
letters.dot" ),
COleVariant( (short)FALSE, VT_BOOL ),
COleVariant( (short)FALSE, VT_BOOL ),
COleVariant( (short)FALSE, VT_BOOL ),
COleVariant( "" ), COleVariant( "" ),
COleVariant( (short)TRUE, VT_BOOL ),
COleVariant( "" ), COleVariant( "" ),
COleVariant( (long)0 ), COleVariant( (long)0 ),
COleVariant( (short)TRUE, VT_BOOL ),
vtOptional,
vtOptional,
vtOptional,
vtOptional);
mailMergeMSWord = docTemplateMSWord.GetMailMerge();
mailMergeMSWord.Execute( COleVariant( (short)FALSE, VT_BOOL ) );
docTemplateMSWord.Close( COleVariant( (long)0 ), COleVariant(
(long)0 ),
COleVariant( (short)FALSE ) );
}
else
{
strMessage += "Generate letters\n";
}
I've been all over trying to apply answers to Word (2000) mail merge related
posts w/ regard to my issue but, to no avail.
My mail merge code used to work w/ Word 2000 and 2002 on NT 4.0 sp6 before
upgrading to Word 2002 sp3 on XP. Now running the code produces a an
exception w/ the following; "This method or property is not available because
the document is not a mail merge main document". The original code had a
dependency upon msword9.olb. I've removed the old dependency and generated
the wrapper classes for MS Word 2003 (msword.olb) and rebuilt. The word
template below has a datasource of a sqlserver table populated by the stored
proc called in the code. All fields match between table and .dot. Stepping
into the code at mailMergeMSWord.Execute, the exception is generated in MFC
code at oledisp2.cpp OleDispatchDriver::InvokeHelperV when a call to
m_lpDispatch->Invoke is made.
Your help would be very much appreciated. Let me know if I can supply more
info.
Regards,
tgul
My VC++ 6.0 code:
BOOL CMyClass : : PrintLetters()
{
CWaitCursor wait;
CString strSQL, strMessage;
_Application appMSWord
try
{
COleVariant vtOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR),
vtFalse((short)FALSE);
appMSWord.CreateDispatch( "Word.Application" );
CString strUserTemplatesPath =
((Options)appMSWord.GetOptions()).GetDefaultFilePath( 15 );
Documents docsMSWord = appMSWord.GetDocuments();
_Document docTemplateMSWord;
MailMerge mailMergeMSWord;
// Generate the letters
strSQL = "{CALL GenerateLetters (" +
pPropertySheet->GetCPIString() + ", '" +
pPropertySheet->GetDDstDayofMonth() + "', '" +
pPropertySheet->GetSelectedMonthYear() + "', '" +
pPropertySheet->GetIncreaseStartDate() + "', '" +
pPropertySheet->GetIncreaseEndDate() + "')}";
CLettersSet rsLetters( GetDb() );
if ( !GetDb()->OpenRecordset( &rsLetters, FALSE,
CRecordset::forwardOnly,
strSQL,
CRecordset::readOnly |
CRecordset::executeDirect ) )
{
appMSWord.ReleaseDispatch();
return FALSE;
}
if ( rsLetters.m_RowCount > 0 )
{
docTemplateMSWord =
docsMSWord.Open( COleVariant( strUserTemplatesPath + "\\generate
letters.dot" ),
COleVariant( (short)FALSE, VT_BOOL ),
COleVariant( (short)FALSE, VT_BOOL ),
COleVariant( (short)FALSE, VT_BOOL ),
COleVariant( "" ), COleVariant( "" ),
COleVariant( (short)TRUE, VT_BOOL ),
COleVariant( "" ), COleVariant( "" ),
COleVariant( (long)0 ), COleVariant( (long)0 ),
COleVariant( (short)TRUE, VT_BOOL ),
vtOptional,
vtOptional,
vtOptional,
vtOptional);
mailMergeMSWord = docTemplateMSWord.GetMailMerge();
mailMergeMSWord.Execute( COleVariant( (short)FALSE, VT_BOOL ) );
docTemplateMSWord.Close( COleVariant( (long)0 ), COleVariant(
(long)0 ),
COleVariant( (short)FALSE ) );
}
else
{
strMessage += "Generate letters\n";
}