This is a demo of using Word with Visual FoxPro to perform a Mail Merge. The Data attached is Free FoxPro table. In a program the table can be created from user selected criteria. The Word file is already setup to work with the set table. I use this with corporate letters that only need the fill in. FoxPro reports works well here but this does give some freedom to the user to modify the letter without programmer intervention.
** change the path and file name to suit
oWord.Documents.Open("C:\wordmail.doc")
** check to make sure the documnet is attached to a
** datasource and ready to merge.
If oWord.ActiveDocument.MailMerge.State = wdMainAndDataSource
oWord.ActiveDocument.MailMerge.Destination = wdSendToPrinter
oWord.ActiveDocument.MailMerge.DataSource.FirstRecord = 1
oWord.ActiveDocument.MailMerge.DataSource.LastRecord = 1
oWord.ActiveDocument.MailMerge.Execute
endif
oWord.Quit(wdDoNotSaveChanges) && close file no save
release oWord
** property to retrive OR set the first record to print
*oWord.ActiveDocument.MailMerge.DataSource.FirstRecord
** property to retrive OR set the last record to print
*oWord.ActiveDocument.MailMerge.DataSource.LastRecord
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.