Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating 1 Word file for multiple merges in VF

Status
Not open for further replies.

amills

Programmer
May 30, 2003
22
US

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
 
amills
Also is there a way to have Word
stay at the forefront after the merge is complete ?


FAQ184-4262

Does the numeric field need to be converted to a character field in the data source ?

Most likely, add a new textfield in your datasource and do an SQL update to transform you numeric values to text.

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.


I don't see how that is possible since you are dealing with 3 (or what ever letters) with mailmerge. It uld be possible if you did not use the mailmerge function, and just created the documents "on-the-fly" and just adding page-breaks rather then a new document.






Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top