Private Sub cmdPrintQuote_Click()
Dim FILENAME As String
Dim objWord As New Word.Application
Dim objDoc As Word.Document
'Make Word visible
objWord.Application.Visible = True
'Sets the Word document to do the mail merging
Set objDoc = objWord.Documents.Open("c:\Quotes\Quote.doc")
objWord.Application.Visible = True
'Set the mail merge data source
objDoc.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\All Users\Desktop\Quotes\QuoteMaster.accdb", _
LinkToSource:=True, Connection:="TABLE tblSendQuote", _
SQLStatement:="SELECT * FROM tblSendQuote]"
objDoc.MailMerge.Destination = wdSendToNewDocument
objDoc.MailMerge.Execute
FILENAME = "Test File.doc"
objWord.Application.Documents(1).SaveAs ("C:\Quotes\" & FILENAME)
objWord.Application.Documents(2).Close wdDoNotSaveChanges
objWord.Application.Documents(FILENAME).Close
Set objWord = Nothing
Set objDoc = Nothing
End Sub
|