Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Word-Access Mail Merged Documents

Status
Not open for further replies.

hoppergs

IS-IT--Management
Feb 24, 2003
39
0
0
GB
Hi

I have some Word documents that are Mail Merged to Access queries. I've written some VBA to an Access form which opens each document, prints them all and then closes Word.

It all works fine apart from the fact that for each document, you manually have to click "OK" each time on the Print Preview pane.

Does anyone know of any code that will stop the user having to do this? The lines I'm using to print the documents are below:

WordDoc.MailMerge.Destination = wdSendToPrinter
WordDoc.MailMerge.Execute

Many thanks

Graham
 
Following is a section of the code I have that works to print without user intervention.


'All setting of main document, etc is done prior to here.
' Execute the mail merge.
wDoc.MailMerge.Destination = wdSendToNewDocument
wDoc.MailMerge.Execute 'execute data merge
wApp.ActiveDocument.PrintOut 'Print new merged document
wApp.ActiveDocument.Close False 'close new doc, no save
wApp.Quit SaveChanges:=wdDoNotSaveChanges 'close Word app


Hope this helps.
Scott
 
Thanks for this Scott. However when I try this it doesn't actually print the merged data - instead it prints the template!

What are you setting wApp as?

Cheers

Graham
 
Graham,

Here's the entire function coding. Hope it helps you.

Function PrintIt() 'sFiletoOutput As String, sFaxTo As String, sFaxNo As String

Dim wApp As New Word.Application
Dim wDoc As Word.Document

On Error GoTo Error_PrintIt

Set wDoc = wApp.Documents.Open(CurrentProject.Path & "\faxmerge.doc") 'Open the mail merge document

' Make Word visible.
wApp.Visible = True

' Set the mail merge data source as the Tracer_data database.
If wDoc.MailMerge.State <> wdMainAndDataSource Then
wDoc.MailMerge.OpenDataSource _
Name:=CurrentProject.Path & &quot;\&quot; & _
&quot;Tracer_data.mdb&quot;, _
ReadOnly:=True, LinkToSource:=True, _
SQLStatement:=&quot;SELECT * FROM [tblOutboundInquiries]&quot;

End If

' Execute the mail merge.
wDoc.MailMerge.Destination = wdSendToNewDocument
wDoc.MailMerge.Execute
wApp.ActiveDocument.PrintOut
wApp.ActiveDocument.Close False
wApp.Quit SaveChanges:=wdDoNotSaveChanges

Set wDoc = Nothing

PrintIt = True
Exit_PrintIt:

Exit Function

Error_PrintIt:

PrintIt = False

Resume Exit_PrintIt:


End Function


Regards,
Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top