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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing form with merged fields

Status
Not open for further replies.

amills

Programmer
May 30, 2003
22
US
Currently I use the following code which merges the document, saves a new merged document, and then closes the activedocument(s) and reload my saved merge document. The end result I want to achieve is to just have the merged document pulled up when the merge is complete. How can I close just the original document with the merge field codes. Closing the Activedocument works but since the new merged doc is the activedocument I have to close both and then reopen .

Below is my code....

** Merge

&&name of form document with merge fields
ofile="F:\FORMS\FORM1.DOC"

&&name of data source
odata="F:\DATA\DATA.DBF"

&&name of new file to be created
nfile="F:\DOCUMENT\FORM2.DOC"

&&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 nfile
oword.ActiveDocument.close()

&&closes ofile
oword.ActiveDocument.close()

&&opens form document
oDocument=oword.Documents.open(nfile)


Andy
 
What you need to do is have the mailmerge open to a new document and then you can close the orginal document

oWord.ActiveDocument.MailMerge.Destination = 0

Do this prior to merging and then you can close
the original document
with

odocument.close()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top