Hi
I have a button on an Access form that opens some Word files that are linked to queries (via Mail Merge) and prints them.
My problem is that it's printing multiple copies of each letter and I don't know why. Most of the queries linked do not have any records in them - not sure if this is causing a problem?
Anyone ever seen this problem before? The code I'm using is below........thanks.
Graham
Dim WordObject As Word.Application
Dim WordDoc As Word.Document
Dim strFilename1, strFilename2, strFilename3, strFilename4, strFilename5, strFilename6, strFilename7, strFilename8, strFilename9, strFilename10, strFilename11, strFilename12, strFilename13, strFilename14, strFilename15, strFilename16 As String
Dim strFilenames(1 To 16) As String
'set values of array (all files to be merged)
strFilenames(1) = "c:\gh\MMMixedNotRegBFA.doc"
strFilenames(2) = "c:\gh\MMMixedNotRegIM.doc"
strFilenames(3) = "c:\gh\MMMixedRegBFA.doc"
strFilenames(4) = "c:\gh\MMMixedRegIM.doc"
strFilenames(5) = "c:\gh\MMNotRegBFA.doc"
strFilenames(6) = "c:\gh\MMNotRegIM.doc"
strFilenames(7) = "c:\gh\MMRegBFA.doc"
strFilenames(8) = "c:\gh\MMRegIM.doc"
strFilenames(9) = "c:\gh\nonMMMixedNotRegBFA.doc"
strFilenames(10) = "c:\gh\nonMMMixedNotRegIM.doc"
strFilenames(11) = "c:\gh\nonMMMixedRegBFA.doc"
strFilenames(12) = "c:\gh\nonMMMixedRegIM.doc"
strFilenames(13) = "c:\gh\nonMMNotRegBFA.doc"
strFilenames(14) = "c:\gh\nonMMNotRegIM.doc"
strFilenames(15) = "c:\gh\nonMMRegBFA.doc"
strFilenames(16) = "c:\gh\nonMMRegIM.doc"
'open word
Set WordObject = CreateObject("Word.Application")
'loop through each file, do a mail merge and then print
For Each file In strFilenames()
Set WordDoc = WordObject.Documents.Open(file)
WordDoc.Application.Visible = True
WordDoc.MailMerge.Destination = wdSendToNewDocument
WordDoc.MailMerge.Execute
WordDoc.Application.Options.PrintBackground = False
WordDoc.Application.ActiveDocument.PrintOut
Next
WordObject.Quit SaveChanges:=wdDoNotSaveChanges 'close Word app
I have a button on an Access form that opens some Word files that are linked to queries (via Mail Merge) and prints them.
My problem is that it's printing multiple copies of each letter and I don't know why. Most of the queries linked do not have any records in them - not sure if this is causing a problem?
Anyone ever seen this problem before? The code I'm using is below........thanks.
Graham
Dim WordObject As Word.Application
Dim WordDoc As Word.Document
Dim strFilename1, strFilename2, strFilename3, strFilename4, strFilename5, strFilename6, strFilename7, strFilename8, strFilename9, strFilename10, strFilename11, strFilename12, strFilename13, strFilename14, strFilename15, strFilename16 As String
Dim strFilenames(1 To 16) As String
'set values of array (all files to be merged)
strFilenames(1) = "c:\gh\MMMixedNotRegBFA.doc"
strFilenames(2) = "c:\gh\MMMixedNotRegIM.doc"
strFilenames(3) = "c:\gh\MMMixedRegBFA.doc"
strFilenames(4) = "c:\gh\MMMixedRegIM.doc"
strFilenames(5) = "c:\gh\MMNotRegBFA.doc"
strFilenames(6) = "c:\gh\MMNotRegIM.doc"
strFilenames(7) = "c:\gh\MMRegBFA.doc"
strFilenames(8) = "c:\gh\MMRegIM.doc"
strFilenames(9) = "c:\gh\nonMMMixedNotRegBFA.doc"
strFilenames(10) = "c:\gh\nonMMMixedNotRegIM.doc"
strFilenames(11) = "c:\gh\nonMMMixedRegBFA.doc"
strFilenames(12) = "c:\gh\nonMMMixedRegIM.doc"
strFilenames(13) = "c:\gh\nonMMNotRegBFA.doc"
strFilenames(14) = "c:\gh\nonMMNotRegIM.doc"
strFilenames(15) = "c:\gh\nonMMRegBFA.doc"
strFilenames(16) = "c:\gh\nonMMRegIM.doc"
'open word
Set WordObject = CreateObject("Word.Application")
'loop through each file, do a mail merge and then print
For Each file In strFilenames()
Set WordDoc = WordObject.Documents.Open(file)
WordDoc.Application.Visible = True
WordDoc.MailMerge.Destination = wdSendToNewDocument
WordDoc.MailMerge.Execute
WordDoc.Application.Options.PrintBackground = False
WordDoc.Application.ActiveDocument.PrintOut
Next
WordObject.Quit SaveChanges:=wdDoNotSaveChanges 'close Word app