The following code is a snapshot of a simple mailmerge from an access 2000 database called lord2.mdb.
This routine works perfectly well if Word is NOT already open but if it is already open , I get a dialog box asking me if I wish to save the changes to the original mail merge document (Agent-Blank.doc) when I try to close it (objWord5.Close SaveChanges:=wdDoNotSaveChange).
Can any one tell me why, if Word is already open , the wdDoNotSaveChange argument is not working?
If Word is not already open, the original mailmerge document (Agent-Blank.doc) closes without any dialog box and leaves me with a new document showing my required data.
Any tips on how to over come this would be appreciated.
Private Sub SendToMerge_Click()
Dim DocToBeUsed As String
Dim QueryToBeUsed As String
Dim objWord5 As Word.Document
DocToBeUsed = "C:\My Documents\Mailmerge\Agent-Blank.doc"
DoCmd.OpenForm "Case", acNormal, , "[CaseNum] = Forms!printanydoc!CaseNum", acFormReadOnly, acHidden
QueryToBeUsed = "printanydoc-case"
Set objWord5 = GetObject(DocToBeUsed, "Word.Document"
objWord5.Application.Visible = True
objWord5.MailMerge.OpenDataSource _
Name:="c:\program files\lla\lord2.mdb", _
LinkToSource:=True, _
Connection:="QUERY " & QueryToBeUsed, _
SQLStatement:="SELECT * FROM " & QueryToBeUsed & " ;"
objWord5.MailMerge.Destination = wdSendToNewDocument
objWord5.MailMerge.Execute
objWord5.Close SaveChanges:=wdDoNotSaveChanges
DoCmd.Close acForm, "Case", acSaveNo
End Sub
This routine works perfectly well if Word is NOT already open but if it is already open , I get a dialog box asking me if I wish to save the changes to the original mail merge document (Agent-Blank.doc) when I try to close it (objWord5.Close SaveChanges:=wdDoNotSaveChange).
Can any one tell me why, if Word is already open , the wdDoNotSaveChange argument is not working?
If Word is not already open, the original mailmerge document (Agent-Blank.doc) closes without any dialog box and leaves me with a new document showing my required data.
Any tips on how to over come this would be appreciated.
Private Sub SendToMerge_Click()
Dim DocToBeUsed As String
Dim QueryToBeUsed As String
Dim objWord5 As Word.Document
DocToBeUsed = "C:\My Documents\Mailmerge\Agent-Blank.doc"
DoCmd.OpenForm "Case", acNormal, , "[CaseNum] = Forms!printanydoc!CaseNum", acFormReadOnly, acHidden
QueryToBeUsed = "printanydoc-case"
Set objWord5 = GetObject(DocToBeUsed, "Word.Document"
objWord5.Application.Visible = True
objWord5.MailMerge.OpenDataSource _
Name:="c:\program files\lla\lord2.mdb", _
LinkToSource:=True, _
Connection:="QUERY " & QueryToBeUsed, _
SQLStatement:="SELECT * FROM " & QueryToBeUsed & " ;"
objWord5.MailMerge.Destination = wdSendToNewDocument
objWord5.MailMerge.Execute
objWord5.Close SaveChanges:=wdDoNotSaveChanges
DoCmd.Close acForm, "Case", acSaveNo
End Sub