Wiki Home

Vfp Mail Merge With Word Problem


Namespace: VFP
i am a new comer to the wikis site, hope i am in the right place.

i created a word document locally and linked it to vfp9.0 free table on the server.
when i run the apps locally it runs perfectly, the word < fields > are filled with the appropriate data from the table. when i run the apps on the server on my machine, it runs perfectly. but when i run the apps from another user's computer through the server it does not work: it gives OLE IDispatch exception code 0 from microsoft word: invalid parameter

this is the code i am using to perform the merge
FUNCTION PrintMerge
LPARAMETERS tcFile,tcRec
**tcfile is the location of the word document on the server
**tcrec is the record i need to merge

	#DEFINE wdMainAndDataSource 2
	#DEFINE wdSendToPrinter 1
	#DEFINE wdDoNotSaveChanges 0
	#DEFINE wdWindowStateMinimize 2

	oWord = CREATEOBJECT("Word.Application")
	oWord.Visible = .f.
	oWord.WindowState = wdWindowStateMinimize

	wconn=gcdocpath+'\'+'connloanapp.odc'
**wconn is the data source i use to connect to the doc.
	oWord.Documents.Open(tcfile)

	oword.ActiveDocument.MailMerge.OpenDataSource(wconn)
**if i comment the above line it still works perfectly on my machine whether locally or through the server

	IF oWord.ActiveDocument.MailMerge.State = wdMainAndDataSource
		 WAIT WINDOW 'in if '+STR(tcrec)
**i know that it stops here and crashes some times gives the error mentioned above or says that the app u r using is not available....
	   oWord.ActiveDocument.MailMerge.DataSource.ActiveRecord = tcrec
**it does get passed this line
	   WAIT WINDOW 'after active record'
	   oWord.ActiveDocument.MailMerge.Destination = wdSendToPrinter
	   oWord.ActiveDocument.MailMerge.DataSource.FirstRecord =  oWord.ActiveDocument.MailMerge.DataSource.ActiveRecord
	   oWord.ActiveDocument.MailMerge.DataSource.LastRecord = oWord.ActiveDocument.MailMerge.DataSource.ActiveRecord
	   oWord.ActiveDocument.MailMerge.Execute
	ENDIF
	oWord.Quit(wdDoNotSaveChanges)  && close file no save
  RELEASE  oWord

RETURN .t.

any help would be appreciated, or a different approach?????????

thanks a million in advance
Category Open Questions, Category Needs Refactoring
( Topic last updated: 2006.09.21 10:44:38 AM )