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 / November 2007

Tip: Looking for answers? Try searching our database.

Word 2000 mail merge broke upgrading to 2002 sp3

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tgul - 25 Nov 2007 04:36 GMT
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";
     }
     .
     .
     .
     appMSWord.SetVisible( TRUE );
  }
  catch( CDBException* peDb )
  {
     MessageBox( peDb->m_strError, "Merge Data Error", MB_OK | MB_ICONSTOP );
     peDb->Delete();
     appMSWord.ReleaseDispatch();
     return FALSE;
  }

  appMSWord.ReleaseDispatch();

  if ( strMessage != "" )
  {
     MessageBox( "No letters needed to be generated for:\n" + strMessage );
  }

  return TRUE;
}
Peter Jamieson - 25 Nov 2007 10:17 GMT
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
)

Signature

Peter Jamieson
http://tips.pjmsn.me.uk

> Hi,
>
[quoted text clipped - 116 lines]
>   return TRUE;
> }
tgul - 27 Nov 2007 03:31 GMT
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

> 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
[quoted text clipped - 131 lines]
> >   return TRUE;
> > }
Peter Jamieson - 27 Nov 2007 09:31 GMT
My guess is that you have this problem:

http://support.microsoft.com/kb/825765/en-us

I didn't mention it before because I thought you would already have
encountered it when working with Word 2002. But maybe that came in a later
SP.

Signature

Peter Jamieson
http://tips.pjmsn.me.uk

> Thanks for the reply.
>
[quoted text clipped - 159 lines]
>> >   return TRUE;
>> > }
tgul - 28 Nov 2007 02:59 GMT
Thanks. Yes this appears to be the fix. I've reproduced it in my development
environment ... Now on to the client. Thanks again.

> My guess is that you have this problem:
>
[quoted text clipped - 167 lines]
> >> >   return TRUE;
> >> > }
 
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.