Hi
I have a script that does a mail merge. At the end of the script I get 2 docs, the original merge doc with all the form fields etc in, and the merged letter.
I would like to close the original document but leave the letter open so it can be edited/saved/printed.
here is my code:
I would like to close file RIA_DG.doc, but can only find methods of closing word, which closes all word docs i have open.
Thanks
Kev
I have a script that does a mail merge. At the end of the script I get 2 docs, the original merge doc with all the form fields etc in, and the merged letter.
I would like to close the original document but leave the letter open so it can be edited/saved/printed.
here is my code:
Code:
DoCmd.SetWarnings False
Dim mypath As String
Dim mypath3 As String
Dim Wordpath As String
Dim folder As String
Dim sDBPath As String
Dim oApp As Word.Application
Dim ThisDB As String
Dim oWord As Word.Document
Dim oMainDoc As Word.Document
Wordpath = Environ("office") & "\winword.exe"
mypath = Left$(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir$(CurrentDb.Name)))
mypath3 = ("" & mypath & "RIA-DG.doc""")
ThisDB = CurrentDb.Name
DoCmd.RepaintObject , ""
DoCmd.OpenQuery "qryPersonAdviserAddress", acViewNormal, acEdit 'create PersonAdviserAddress Table
DoCmd.OpenQuery "qryPAAStLetterLLAgent", acViewNormal, acEdit ' create RIALetterExport Table
folder = CurrentProject.Path & "\"
Set oApp = CreateObject("Word.Application")
Set oWord = oApp.Documents.Open(FileName:=mypath3)
oApp.Visible = True
With oWord.MailMerge
.MainDocumentType = wdFormLetters
sDBPath = ThisDB
.OpenDataSource Name:=sDBPath, _
SQLStatement:="SELECT * FROM [tblRIALetterExport]"
End With
With oWord
.MailMerge.Destination = wdSendToNewDocument
.MailMerge.Execute
End With
oApp.Activate
oApp.Documents.Parent.Visible = True
oApp.Application.WindowState = 1
oApp.ActiveWindow.WindowState = 1
I would like to close file RIA_DG.doc, but can only find methods of closing word, which closes all word docs i have open.
Thanks
Kev