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

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
   
pvp1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Russell LibbySoftware Engineer, Advisory Commented:

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
pvp1Author Commented:
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
Russell LibbySoftware Engineer, Advisory Commented:

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
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

pvp1Author Commented:
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
Russell LibbySoftware Engineer, Advisory Commented:

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pvp1Author Commented:
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
pvp1Author Commented:
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
Russell LibbySoftware Engineer, Advisory Commented:

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
Russell LibbySoftware Engineer, Advisory Commented:

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
Russell LibbySoftware Engineer, Advisory Commented:

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
Russell LibbySoftware Engineer, Advisory Commented:

Sorry for the triple posts, EE was not posting correctly....
Russell
0
pvp1Author Commented:
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
Russell LibbySoftware Engineer, Advisory Commented:

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

pvp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.