I want to print Word 2000 mail-merged letters for my VFP application. For example I have created a document in Word “Myletter.doc” and bookmarked the fields “contact” and “company”. Then in the application I have used this code:
USE customers
public oWord
scan
oWord=CREATEOBJECT("Word.Basic"
oWord.FileOpen ("myletter.doc"
oWord. ww7_EditGoto ("contact"
oWord.Insert (customers.Contact)
oWord. ww7_EditGoTo ("company"
oWord.Insert (customers.Company)
oWord.FilePrint
wait window 'Printing please wait...' timeout(1)
oWord.FileSaveAs("tempword.doc"
oWord.AppClose()
endscan
release oWord
It seem to work ok, but I wonder if there is something better. It seems that I shouldn’t have to create and new instance of Word every time I step to the next record, but if I don’t I get ole errors. The “wait” command seems useless, but without it I get a message that I shouldn’t close word when it is trying to print. And the FileSaveAs command also seems unnecessary but required to keep my original document in tact.
Is there some better code I should use?
Thanks…Rick
USE customers
public oWord
scan
oWord=CREATEOBJECT("Word.Basic"
oWord.FileOpen ("myletter.doc"
oWord. ww7_EditGoto ("contact"
oWord.Insert (customers.Contact)
oWord. ww7_EditGoTo ("company"
oWord.Insert (customers.Company)
oWord.FilePrint
wait window 'Printing please wait...' timeout(1)
oWord.FileSaveAs("tempword.doc"
oWord.AppClose()
endscan
release oWord
It seem to work ok, but I wonder if there is something better. It seems that I shouldn’t have to create and new instance of Word every time I step to the next record, but if I don’t I get ole errors. The “wait” command seems useless, but without it I get a message that I shouldn’t close word when it is trying to print. And the FileSaveAs command also seems unnecessary but required to keep my original document in tact.
Is there some better code I should use?
Thanks…Rick