INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

COM and Automation

Mail merge Word Document to Database by danceman
Posted: 7 Sep 02

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.

Here is the FoxPro code

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

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

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

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close