P
Phill
I am trying to create a new mailmerge document from Access, close the
template, and save the file so that I can email it. The problem is after I
close the template I don't have a reference to the new document created.
This is my code:
'-- Create the OLE instance of Word, then activate it.
Set WordApp = CreateObject("Word.Application")
Set WordDoc = WordApp.Documents.Add(Template:= _
Path & WordTemplate, _
NewTemplate:=False)
'Set WordDoc = GetObject(strFinalDoc, "Word.Document")
WordDoc.Application.Visible = True
WordDoc.MailMerge.OpenDataSource _
Name:=CurrentDb.Name, _
LinkToSource:=True, _
ReadOnly:=True, _
SQLStatement:="SELECT * FROM qryRptROW", _
subtype:=wdMergeSubTypeWord2000
WordDoc.MailMerge.Execute
WordDoc.Close False
If Dir("C:\Right-of-Way-Request.doc") <> "" Then
Kill "C:\Right-of-Way-Request.doc"
End If
WordDoc.ActiveWindow.Activate
WordDoc.SaveAs "C:\Right-of-Way-Request.doc"
Set WordDoc = Nothing
template, and save the file so that I can email it. The problem is after I
close the template I don't have a reference to the new document created.
This is my code:
'-- Create the OLE instance of Word, then activate it.
Set WordApp = CreateObject("Word.Application")
Set WordDoc = WordApp.Documents.Add(Template:= _
Path & WordTemplate, _
NewTemplate:=False)
'Set WordDoc = GetObject(strFinalDoc, "Word.Document")
WordDoc.Application.Visible = True
WordDoc.MailMerge.OpenDataSource _
Name:=CurrentDb.Name, _
LinkToSource:=True, _
ReadOnly:=True, _
SQLStatement:="SELECT * FROM qryRptROW", _
subtype:=wdMergeSubTypeWord2000
WordDoc.MailMerge.Execute
WordDoc.Close False
If Dir("C:\Right-of-Way-Request.doc") <> "" Then
Kill "C:\Right-of-Way-Request.doc"
End If
WordDoc.ActiveWindow.Activate
WordDoc.SaveAs "C:\Right-of-Way-Request.doc"
Set WordDoc = Nothing