M
Mike_Gator14
Hi, I would like to perform a mailmerge from within access to word.
I have a word document that is divided into different printable
sections, based on a value in an access query, f.i.
if the value is 1 then print section 1, 6 and 7
if the value is 2 then print section 2 and 4
etc.
In each record this value is checked and then the matching sections
are to be printed out.
In word I can do it like this:
Documents("Name.doc").MailMerge.DataSource.ActiveRecord =
wdFirstRecord
If ActiveDocument.MailMerge.DataSource.DataFields("Name").Value = 1
Then
Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:=
_
wdPrintDocumentContent, Copies:=1, Pages:="s1, s6, s7", PageType:= _
wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False,
_
PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
End If
etc.
and everything works fine
How I can do the same but then from access?
I have 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.Destination = wdSendToPrinter
objWord.MailMerge.Execute
I guess the code has to be somewhere at the 'wdSendToPrinter', but I
haven't got a clue.
Thank you,
Mike
I have a word document that is divided into different printable
sections, based on a value in an access query, f.i.
if the value is 1 then print section 1, 6 and 7
if the value is 2 then print section 2 and 4
etc.
In each record this value is checked and then the matching sections
are to be printed out.
In word I can do it like this:
Documents("Name.doc").MailMerge.DataSource.ActiveRecord =
wdFirstRecord
If ActiveDocument.MailMerge.DataSource.DataFields("Name").Value = 1
Then
Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:=
_
wdPrintDocumentContent, Copies:=1, Pages:="s1, s6, s7", PageType:= _
wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False,
_
PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
End If
etc.
and everything works fine
How I can do the same but then from access?
I have 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.Destination = wdSendToPrinter
objWord.MailMerge.Execute
I guess the code has to be somewhere at the 'wdSendToPrinter', but I
haven't got a clue.
Thank you,
Mike