pvp1
asked on
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.O penDataSou rce()' 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
For my application purpose i have to open the data source for some word documents. For that i am using 'WordDocument1.MailMerge.O
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
ASKER
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.UpdateDataSourcePro c(FileName :OleVarian t);
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(F ileName, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam);
WordDocument1.ConnectTo(Wo rdApplicat ion1.Activ eDocument) ;
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.Op enDataSour ce(SrcName , EP, ConfConv, ReadOnly, LinkToSrc, AddToRecent, PWordDoc, PWordTemplate, EP,
WritePWordDoc, WritePWordTemplate, Conn, SQL, SQL1,EP,EP);
WordDocument1.SaveAs(filen ame);
WordDocument1.Disconnect;
WordApplication1.Quit;
WordApplication1.Disconnec t;
end;
--> please explain me clearly what i have to do, or any other easy solution to avoid exception with word 97.
regards
pvp
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.UpdateDataSourcePro
var
SrcName, EP, ConfConv, ReadOnly, LinkToSrc : OleVariant;
AddToRecent, PWordDoc, PWordTemplate : OleVariant;
WritePWordDoc, WritePWordTemplate, Conn : OleVariant;
SQL, SQL1, Pause : OleVariant;
begin
WordApplication1.Connect;
WordApplication1.Documents
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam);
WordDocument1.ConnectTo(Wo
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.Op
WritePWordDoc, WritePWordTemplate, Conn, SQL, SQL1,EP,EP);
WordDocument1.SaveAs(filen
WordDocument1.Disconnect;
WordApplication1.Quit;
WordApplication1.Disconnec
end;
--> please explain me clearly what i have to do, or any other easy solution to avoid exception with word 97.
regards
pvp
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.UpdateDataSourcePro
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
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam);
WordDocument1.ConnectTo(Wo
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.OpenDataSo
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
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
ASKER
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.CreateObjectF romFile(Ha uptpfad+'w ord1.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
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.CreateObjectF
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
Not my area of expertise....
But I believe you need to call the Execute method on the MailMerge object
eg;
WordDocument1.MailMerge.Ex
Hope this helps,
Russell
Not my area of expertise....
But I believe you need to call the Execute method on the MailMerge object
eg;
WordDocument1.MailMerge.Ex
Hope this helps,
Russell
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.Ex
Hope this helps,
Russell
Sorry for the triple posts, EE was not posting correctly....
Russell
ASKER
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.CreateObjectF romFile(Ha uptpfad+'w ord1.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
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.CreateObjectF
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
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
ASKER
Thants ok. Any way thnaks for your help!!
pvp
pvp
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