S
scott
From Access, I have a Mail Merge button that lauches a Word template with
labels that populates it with database records. After the code finishes, i'm
left with 2 word docs open. 1 is the template doc that i do not wish to save
and the merged word label doc with the data.
On my access form that contains the Mail Merge button, i have a Close button
that runs CloseWord()
When I click Close button, Word displays the Save dialog on the
labeladdress.doc template file. I never want the user to save the template
file and would like to close it without the dialog to display the Save
dialog option.
Is this possible?
=========================================================================
Public gobjWord As Word.Application
Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("C:\data\labeladdress.doc",
"Word.Document")
' Make Word visible.
objWord.Application.Visible = True
objWord.MailMerge.OpenDataSource _
Name:="C:\data\" & _
"company_data.mdb", _
LinkToSource:=True, _
Connection:="TABLE tblEmployees", _
SQLStatement:="Select * from [tblEmployees]"
objWord.MailMerge.Execute
End Function
Function CreateWordObj()
On Error GoTo CreateWordObj_Err
CreateWordObj = False
'Attempt to Launch Word
Set gobjWord = New Word.Application
CreateWordObj = True
CreateWordObj_Exit:
Exit Function
CreateWordObj_Err:
MsgBox "Couldn't Launch Word!!", vbCritical, "Warning!!"
CreateWordObj = False
Resume CreateWordObj_Exit
End Function
Sub CloseWord()
If Not gobjWord Is Nothing Then
gobjWord.Quit
End If
CloseWord_Exit:
Set gobjWord = Nothing
Exit Sub
CloseWord_Err:
MsgBox "Error # " & Err.Number & ": " & Err.Description
Resume CloseWord_Exit
End Sub
labels that populates it with database records. After the code finishes, i'm
left with 2 word docs open. 1 is the template doc that i do not wish to save
and the merged word label doc with the data.
On my access form that contains the Mail Merge button, i have a Close button
that runs CloseWord()
When I click Close button, Word displays the Save dialog on the
labeladdress.doc template file. I never want the user to save the template
file and would like to close it without the dialog to display the Save
dialog option.
Is this possible?
=========================================================================
Public gobjWord As Word.Application
Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("C:\data\labeladdress.doc",
"Word.Document")
' Make Word visible.
objWord.Application.Visible = True
objWord.MailMerge.OpenDataSource _
Name:="C:\data\" & _
"company_data.mdb", _
LinkToSource:=True, _
Connection:="TABLE tblEmployees", _
SQLStatement:="Select * from [tblEmployees]"
objWord.MailMerge.Execute
End Function
Function CreateWordObj()
On Error GoTo CreateWordObj_Err
CreateWordObj = False
'Attempt to Launch Word
Set gobjWord = New Word.Application
CreateWordObj = True
CreateWordObj_Exit:
Exit Function
CreateWordObj_Err:
MsgBox "Couldn't Launch Word!!", vbCritical, "Warning!!"
CreateWordObj = False
Resume CreateWordObj_Exit
End Function
Sub CloseWord()
If Not gobjWord Is Nothing Then
gobjWord.Quit
End If
CloseWord_Exit:
Set gobjWord = Nothing
Exit Sub
CloseWord_Err:
MsgBox "Error # " & Err.Number & ": " & Err.Description
Resume CloseWord_Exit
End Sub