Solved

Error while calling 'WordDocument1.MailMerge.OpenDataSource()' .method

Posted on 2003-12-03
14
1,068 Views
Last Modified: 2007-12-19
Hello All,

         For my application purpose i have to open the data source for some word documents. For that i am using  'WordDocument1.MailMerge.OpenDataSource()'  method. This is working sucessfully with 'MicrosoftwordXP' and raising exception when the application is running with 'Microsoftword 97'. For some specific purposes i had to execute the application using 'Word 97'

The Exception, executing with 'Word 97' is:

  'EAccessVoilation with message 'Access voilation at address 77D8550A' in module 'RPCRT4.dll'. Read of address 00000000'

Could you explain me  how can i solve this problem

thanks
pvp
   
0
Comment
Question by:pvp1
  • 8
  • 6
14 Comments
 
LVL 26

Expert Comment

by:Russell Libby
Comment Utility

pvp,

When you built your application, did you use the type library information for word?(basically what Im asking is; are you using early bound methods, or late bound calls?). If you bound to the type library unit, then there is a pretty good chance that the older function expects more/less (most likely less) params then the newer version. Let me know if this is the case, and I can show you how to call this method using a late bound tequnique, while still keeping everything else early bound.

Regards,
Russell
0
 

Author Comment

by:pvp1
Comment Utility
Hello Russell!

       I am beginner to the programming! so dont have idea of type library information and early bound, latebound methods.

i am providing my source code here, which is working with 'wrod XP':

 procedure TForm1.UpdateDataSourceProc(FileName:OleVariant);
var
  SrcName, EP, ConfConv, ReadOnly, LinkToSrc : OleVariant;
  AddToRecent, PWordDoc, PWordTemplate       : OleVariant;
  WritePWordDoc, WritePWordTemplate, Conn    : OleVariant;
  SQL, SQL1, Pause                           : OleVariant;

begin


  WordApplication1.Connect;
  WordApplication1.Documents.OpenOld(FileName, EmptyParam, EmptyParam,
                                     EmptyParam, EmptyParam, EmptyParam,
                                     EmptyParam, EmptyParam, EmptyParam,
                                     EmptyParam);

    WordDocument1.ConnectTo(WordApplication1.ActiveDocument);

    SrcName := GetCurrentDir + '\param.mdb';
    EP := EmptyParam;
    ConfConv := False;
    ReadOnly := False;
    LinkToSrc := True;
    AddToRecent := False;
    PWordDoc := '';
    PWordTemplate := '';
    WritePWordDoc := '';
    WritePWordTemplate := '';
    Conn := 'TABLE param';
    SQL := '';
    SQL1 := '';


    WordDocument1.MailMerge.OpenDataSource(SrcName, EP, ConfConv, ReadOnly, LinkToSrc, AddToRecent, PWordDoc, PWordTemplate, EP,
      WritePWordDoc, WritePWordTemplate, Conn, SQL, SQL1,EP,EP);


  WordDocument1.SaveAs(filename);
  WordDocument1.Disconnect;
  WordApplication1.Quit;
  WordApplication1.Disconnect;
end;

--> please explain me clearly what i have to do, or any other easy solution to avoid exception with word 97.

regards
pvp
0
 
LVL 26

Expert Comment

by:Russell Libby
Comment Utility

Okay,
You are using early bound methods, and these have been built on a later version of word than you are trying to automate. In the version (XP) of word that the code was generated on, the OpenDataSource(...) method takes 16 parameters. In Word 97, only 14 parameters were expected. The easiest way around this is to cast the WordDocument1 object to a variant (IDispatch), and then perform the late bound call.

See code below:

procedure TForm1.UpdateDataSourceProc(FileName:OleVariant);
var
  SrcName, EP, ConfConv, ReadOnly, LinkToSrc : OleVariant;
  AddToRecent, PWordDoc, PWordTemplate       : OleVariant;
  WritePWordDoc, WritePWordTemplate, Conn    : OleVariant;
  SQL, SQL1, Pause                           : OleVariant;
  pvDoc: Variant;
begin


  WordApplication1.Connect;
  WordApplication1.Documents.OpenOld(FileName, EmptyParam, EmptyParam,
                                     EmptyParam, EmptyParam, EmptyParam,
                                     EmptyParam, EmptyParam, EmptyParam,
                                     EmptyParam);

    WordDocument1.ConnectTo(WordApplication1.ActiveDocument);

    SrcName := GetCurrentDir + '\param.mdb';
    EP := EmptyParam;
    ConfConv := False;
    ReadOnly := False;
    LinkToSrc := True;
    AddToRecent := False;
    PWordDoc := '';
    PWordTemplate := '';
    WritePWordDoc := '';
    WritePWordTemplate := '';
    Conn := 'TABLE param';
    SQL := '';
    SQL1 := '';

    // Get IDispatch interface and make the late bound call (this should work
    // for both versions
    pvDoc:=WordDocument1 as IDispatch;
    pvDoc.MailMerge.OpenDataSource(SrcName, EP, ConfConv, ReadOnly, LinkToSrc, AddToRecent, PWordDoc, PWordTemplate, EP,
      WritePWordDoc, WritePWordTemplate, Conn, SQL, SQL1);

   // Rest of your code
   // ...
   //

Basically, what MS has done is to extend the methods by adding additional (and in most cases optional) parameters to the existsing methods. What you should be doing is programming against the lowest version that you plan on supporting, or you may end up running into more of these issues.

Regards,
Russell

0
 

Author Comment

by:pvp1
Comment Utility
Hello Russell,

           Thanks for your supporting in my problem!

I fallowed your changed source code, but now i have got an exception at:
     pvDoc:=WordDocument1 as IDispatch;

The Exception is:
      'class EIntfCastError with message 'Interface not supported'

How can i solve this exception?

Regards,
pvp
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 50 total points
Comment Utility

Sorry, the wrapper you are using hides the actual com object, and only exposes IUnknown (via TOleServer). This should fix it for you.

  pvDoc:=WordDocument1.DefaultInterface as IDispatch;


Russell

0
 

Author Comment

by:pvp1
Comment Utility
Hello Russell,

     Thanks for your continuous support!   Your support helped me a lot.  Now it is working. But i have to test entire application, if there are any problems regarding this i will ask you.

Regards,
pvp  

0
 

Author Comment

by:pvp1
Comment Utility
Hello Russell,

         Again to you! now i tested entire application(it is using for reporting purpose with OLE continer), but i am getting un synchronized data in to the reports.
 i am using
        OleContainer.CreateObjectFromFile(Hauptpfad+'word1.doc',false); to generate reports.

The only change that i have made: earlier my database(param.mdb) has created in Access XP, but to work with word 97 i changed the format of database to Access 97 and the changes for opendatasource() method as you suggested.

Before changing the database format the application was running perfectly with wrod xp.

Could you suggest me How can i get the synchronized data into my reports.

Regards
pvp


0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 26

Expert Comment

by:Russell Libby
Comment Utility

Not my area of expertise....
But I believe you need to call the Execute method on the MailMerge object

eg;

WordDocument1.MailMerge.Execute;

Hope this helps,
Russell

0
 
LVL 26

Expert Comment

by:Russell Libby
Comment Utility

Not my area of expertise....
But I believe you need to call the Execute method on the MailMerge object

eg;

WordDocument1.MailMerge.Execute;

Hope this helps,
Russell

0
 
LVL 26

Expert Comment

by:Russell Libby
Comment Utility

Well, this is not my area of expertise (I deal more with the COM based issues)....
but I believe you need to call the Execute method on the MailMerge object

eg;

WordDocument1.MailMerge.Execute;

Hope this helps,
Russell

0
 
LVL 26

Expert Comment

by:Russell Libby
Comment Utility

Sorry for the triple posts, EE was not posting correctly....
Russell
0
 

Author Comment

by:pvp1
Comment Utility
Hello,

          It's ok. ADO conncetion + Access 2000 is working fine. But when i changed the Access 2000 Format to Access 97 Format i am facing un synchronization of data. But i had to have Access 97 format for some specific purpose.
         now i changed the database format to Access 97 and befor each call OleContainer.CreateObjectFromFile(Hauptpfad+'word1.doc',false), i am using 'sleep(4000)' now i am getting synchronized data. That fine.

         the main problem with with MSoffice 97(Access 97), while reading the Access 2000 Format, it is telling unrecognizable data format. So that i had to use this Sleep() method.

         Do you know is there any way to read Access 2000 format using Access 97?

Regards,
pvp
0
 
LVL 26

Expert Comment

by:Russell Libby
Comment Utility

Sorry but no, the 97 version pre-dates the 2000 version, thus has no knowledge of any updates/changes/etc made to the 2000 format.


Russell
0
 

Author Comment

by:pvp1
Comment Utility
Thants ok. Any way thnaks for your help!!

pvp
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now