• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

Opening merge document from access


I've written the following code to open a word document.  It works but when opening a merge document, the merge is not executed.  However, when I open the document, it executes the merge.  I'm not sure what is wrong. Thanks.

Public Sub PrintExternalWordDocs(strDocPath As String)
    ' Comments:
    ' Params  : strDocPath
    ' Modified:
    On Error GoTo PROC_ERR
    Dim intStrLength As Integer
    Dim strDocName As String
    Dim objWord As Object
    Set objWord = CreateObject("Word.Application")
    Dim wdSendtoNewDocument As String
    Dim objPrinter As Printer
    Set objPrinter = Application.Printer
    With objWord
        .Activeprinter = objPrinter.DeviceName
        .Visible = True
        .Documents.Open (strDocPath)
    End With
    Set objWord = Nothing
    Exit Sub
    MsgBox Err.Number & vbTab & Err.Description, vbCritical, "basPrintExternalDocuments.PrintExternalWordDocs"
    Resume PROC_EXIT
End Sub

Open in new window

Juan Velasquez
Juan Velasquez
  • 2
1 Solution
Helen FeddemaCommented:
Here is some code to create a merge document from a template (and perform the merge):
   With doc
      .MailMerge.OpenDataSource Name:=strTextFile, _
      If Nz(InStr(strTemplateName, "Label")) > 0 Then
         .MailMerge.MainDocumentType = wdMailingLabels
         .MailMerge.MainDocumentType = wdFormLetters
      End If
      .MailMerge.Destination = wdSendToNewDocument
      'Set another Document variable to the newly merged document,
      'to ensure that the correct document is saved
      Set docMerge = appWord.ActiveDocument
      .Close savechanges:=wdDoNotSaveChanges
   End With
   docMerge.SaveAs2 strSaveNamePath

Open in new window

In this case, the merge document has a text file as the record source, filled from an Access query.  This is a segment of much longer code from my Working with Word ebook.
Juan VelasquezAuthor Commented:
In my case, I am using an access query on an access database.  The merge document is a preexisting document.  I am just trying to open the merge document from Access and have it execute its merge.  Much like opening the document and having the merge execute.  The user will be printing the document when it opens and will then close it where it will be saved to the same location it was opened from
Juan VelasquezAuthor Commented:
Thanks again
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now