Word 2000 mail merge broke upgrading to 2002 sp3

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";
}
 
P

Peter Jamieson

1. Can you clarify which versions of Word you are trying to use (you mention
2000 and 2002, but also 2003. Is 2003 a typo?), and on which versions you
are seeing the problems?

2. Are you using the same .Name, .Querystring and .Connectstring for both
2000 and 2002? Can you discover their values immediately prior to the
..Execute?

(I suppose you have already checked:
a. that the stored procedure is still succeeding, i.e. there is no apparent
problem in the ADO code
b. that you can still set up the mail merge main document manually to
connect to the table you are populating with your procedure
)
 
T

tgul

Thanks for the reply.

The template and application code were originally developed to use Word
2000. Along the way Word was upgraded to 2002. Still worked. When sp3 for
Word 2002 was applied the code broke. The template is fine. The stored proc
executes as always. Opening the template "manually" against the datasource
works.

I am attempting to fix it w/ Word 2003 installed on my developement
environment. I whacked the orginal Word 2000 dependencies and rebuit w/ the
2003 dependencies. Whether Word 2002 sp3 or 2003, the Execute method fails w/
the exception "This method or property is not available because the document
is not a mail merge main document".

-tg
 
T

tgul

Thanks. Yes this appears to be the fix. I've reproduced it in my development
environment ... Now on to the client. Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top