I am trying to create a letter merge routine that will merge multiple letters into one Word document. Is there a way to append a merge into an existing file in Word ? Currenty I have a form with a list box displaying the records to be merged. When the user presses [F6] it creates the dbf file for the data source and then executes the code below.
** Merge Letters
&&name of form document with merge fields
ofile="&path\&filename"
&&name of data source
odata="&path\&filename"
&&name of new file to be created
nfile="&path\&filename"
&&opens Word in VFP
oWord = createobject("Word.Application"
&&does not display Word
oWord.visible = .F.
&&opens form document
oDocument=oword.Documents.open(ofile)
&& Establishes merge document as formletter
oDocument.MailMerge.MainDocumentType= 0
&& Changes Data Source to odata
oDocument.MailMerge.OpenDataSource(odata)
&&Executes merge
oDocument.MailMerge.execute()
&&Saves merged document
oWord.ActiveDocument.SaveAs(nfile)
&&closes ofile
oword.ActiveDocument.close()
&&closes nfile
oword.ActiveDocument.close()
&& Display Word
oWord.visible = .T.
&&opens form document
oDocument=oword.Documents.open(nfile)
********************
That code works to merge one set of letters and I can create a routine to merge the (3) different letter
formsts as separate documents, but I really want it to create one file. Also is there a way to have Word
stay at the forefront after the merge is complete ? Currently it minimizes Word and brings Visual Foxpro to
the forefront. I also noticed that my numeric fields from the databases are only displaying 1 place after the
decimal place (ex. 525.0). Does the numeric field need to be converted to a character field in the data source ?
Andy