M
Mike_Gator14
Hi, I have another question with the following code:
stMergeDoc = "E:\Name.doc"
Set objWord = GetObject(stMergeDoc, "Word.Document")
objWord.Application.Visible = True
objWord.MailMerge.OpenDataSource _
Name:=CurrentDb.Name, _
LinkToSource:=True, _
Connection:="QUERY QryName", _
SQLStatement:="Select * from [QryName]"
objWord.MailMerge.Execute
When I use this code, I get 2 word documents, the original 'name.doc'
and a merged document.
I want to close the original, then print the merged document and then
close the merged one also, all without saving.
If InStr(ActiveDocument.Name, "Name") = 0 Then
Set DocResult = Documents(1)
Else
Set DocResult = ActiveDocument
End If
objWord.Close SaveChanges:=wdDoNotSaveChanges (this closes the
original doc)
'print docresult'
DocResult.Close SaveChanges:=wdDoNotSaveChanges (this closes the
merged doc)
Word.Application.Quit (this closes word)
Set objWord = Nothing
Set DocResult = Nothing
If I run this code, the first time everything works fine. But when I
run it immediately again, the DocResult remains empty! If I manually
close the word-docs, everything works again 1 time, but after that
again DocResult = Empty.
Any ideas?
Thanks, Mike
stMergeDoc = "E:\Name.doc"
Set objWord = GetObject(stMergeDoc, "Word.Document")
objWord.Application.Visible = True
objWord.MailMerge.OpenDataSource _
Name:=CurrentDb.Name, _
LinkToSource:=True, _
Connection:="QUERY QryName", _
SQLStatement:="Select * from [QryName]"
objWord.MailMerge.Execute
When I use this code, I get 2 word documents, the original 'name.doc'
and a merged document.
I want to close the original, then print the merged document and then
close the merged one also, all without saving.
If InStr(ActiveDocument.Name, "Name") = 0 Then
Set DocResult = Documents(1)
Else
Set DocResult = ActiveDocument
End If
objWord.Close SaveChanges:=wdDoNotSaveChanges (this closes the
original doc)
'print docresult'
DocResult.Close SaveChanges:=wdDoNotSaveChanges (this closes the
merged doc)
Word.Application.Quit (this closes word)
Set objWord = Nothing
Set DocResult = Nothing
If I run this code, the first time everything works fine. But when I
run it immediately again, the DocResult remains empty! If I manually
close the word-docs, everything works again 1 time, but after that
again DocResult = Empty.
Any ideas?
Thanks, Mike