Results 1 to 6 of 6
  1. #1
    labessade is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    3

    Word Merge and Print

    Hi all, not sure if I need to ask this in a Word forum but... I have the following code which creates a new WORD document from a mail merge WORD template (linked to a text file as data source - had problems/errors trying to link to Access query direct due to database having a password and we don't use workgroups). I have used late binding so it will work with any office version without requiring a library reference, we develop in Office 2010. This all works but I am trying to print automatically and the code I found for this (.ActiveDocument.PrintOut Background:=False) errors with 'object doesn't support this property or method'. What am I doing wrong please? Thanks

    With WdApp
    .DisplayAlerts = False
    .Application.Visible = True
    Set wdDoc = .Documents.Open(FileName:=strMainDocNm)
    With wdDoc
    With .MailMerge


    .MainDocumentType = wdFormLetters
    'OpenDataSource(Name, Format, ConfirmConversions, ReadOnly, LinkToSource, _
    'AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, _
    'WritePasswordDocument, WritePasswordTemplate, Connection, _
    'SQLStatement, SQLStatement1, OpenExclusive, SubType)
    .OpenDataSource Name:=strDataDocNm, LinkToSource:=True
    .Destination = wdSendToNewDocument ' wdSendToPrinter (prints only)
    .Execute
    .ActiveDocument.PrintOut Background:=False
    '.SaveAs SaveFolderPath & "\" & FirstLetter & "\MailMerge.doc"
    .Close SaveChanges:=False
    End With
    End With
    '.Application.Quit SaveChanges:=False
    End With

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    A stab in the dark because never done mail merge. Possibly because ActiveDocument nested in the With .MailMerge and maybe should be outside that group under With wdDoc. Same for SaveAs and Close.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    labessade is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    3

    Prints but incorrect document

    Quote Originally Posted by June7 View Post
    A stab in the dark because never done mail merge. Possibly because ActiveDocument nested in the With .MailMerge and maybe should be outside that group under With wdDoc. Same for SaveAs and Close.
    Thanks for suggesting this, it does now work without errors and prints BUT - it prints the template rather than the new document created with the merged data.... ?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Google: Access vba Word merge print

    Found http://p2p.wrox.com/access-vba/30118...utomation.html:

    which shows:

    With objApp
    .ActiveDocument.MailMerge.Execute Pause:=True
    .ActiveDocument.PrintOut Background:=False
    .ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges 'Avoid Saving over your template
    .Quit SaveChanges:=wdDoNotSaveChanges 'close all documents
    End With
    Last edited by June7; 10-11-2012 at 12:08 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    labessade is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    3
    Thanks June7, got this working now although I do get a strange error.... after the code has run it produces a MS Access error which just states 'Permission Denied' and an OK button. I have put a breakpoint in to see where the error occurs but if I do that it doesn't error!! Everything seems to work as it should so I am not sure why the error occurs and how to stop it

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Comment out the Close and Quit lines. Does the error still occur? Maybe only need the Quit line.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Mail merge with word
    By alexc333 in forum Access
    Replies: 0
    Last Post: 07-26-2011, 12:06 PM
  2. Word Doc Merge
    By ajolson1964 in forum Access
    Replies: 5
    Last Post: 05-10-2011, 11:50 AM
  3. Mail merge from from Access to Word
    By williamgladstone in forum Access
    Replies: 1
    Last Post: 03-22-2011, 12:00 PM
  4. Word Merge Report
    By Wayne311 in forum Reports
    Replies: 13
    Last Post: 02-21-2011, 12:03 AM
  5. Reports, Word and merge
    By Wayne311 in forum Reports
    Replies: 7
    Last Post: 02-12-2011, 06:29 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums