Solved

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

Posted on 2003-12-03
14
1,079 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
ID: 9866781

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
ID: 9867439
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
ID: 9867602

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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:pvp1
ID: 9867853
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
ID: 9868189

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
ID: 9868451
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
ID: 9868975
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
 
LVL 26

Expert Comment

by:Russell Libby
ID: 9869056

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
ID: 9869069

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
ID: 9869079

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
ID: 9869361

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

Author Comment

by:pvp1
ID: 9875079
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
ID: 9875122

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
ID: 9875359
Thants ok. Any way thnaks for your help!!

pvp
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

792 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