Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2003-12-03
14
Medium Priority
?
1,103 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 200 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

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.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

618 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