This code was the example code in Q159328 of Microsoft.com and applied it to my form.
It worked fine except it's supposed to pull the data from a 3 parameter query.
When I changed the line of code to this:
Connection:="QUERY qryToolAssy", _
SQLStatement:="Select * from [Layout]", it prompted me twice of the 3 parameters?
Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("J:\Shared\WorkingFolder\LayoutMaster.doc", "Word.Document"
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the MACH_4 database.
objWord.MailMerge.OpenDataSource _
Name:="J:\Shared\WorkingFolder\MACH_4.mdb", _
LinkToSource:=True, _
Connection:="TABLE Layout", _
SQLStatement:="Select * from [Layout]"
'Execute the mail merge.
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute
'The following line must follow the Execute statement because the
'PrintBackground property is available only when a document window is
'active. Without this line of code, the function will end before Word
'can print the merged document.
objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut
'MEGA IMPORTANT - ALWAYS RELEASE THE OBJECTS - SAVE MEMORY - INCREASE PERFORMANCE.
objWord.Close
Set objWord = Nothing
End Function
Thanks!
It worked fine except it's supposed to pull the data from a 3 parameter query.
When I changed the line of code to this:
Connection:="QUERY qryToolAssy", _
SQLStatement:="Select * from [Layout]", it prompted me twice of the 3 parameters?
Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("J:\Shared\WorkingFolder\LayoutMaster.doc", "Word.Document"
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the MACH_4 database.
objWord.MailMerge.OpenDataSource _
Name:="J:\Shared\WorkingFolder\MACH_4.mdb", _
LinkToSource:=True, _
Connection:="TABLE Layout", _
SQLStatement:="Select * from [Layout]"
'Execute the mail merge.
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute
'The following line must follow the Execute statement because the
'PrintBackground property is available only when a document window is
'active. Without this line of code, the function will end before Word
'can print the merged document.
objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut
'MEGA IMPORTANT - ALWAYS RELEASE THE OBJECTS - SAVE MEMORY - INCREASE PERFORMANCE.
objWord.Close
Set objWord = Nothing
End Function
Thanks!