Results 1 to 1 of 1
  1. #1
    Join Date
    Dec 2012

    Unanswered: Send current record to Word template

    Hi all,

    I'm trying to send information from access 2010 form to a 2010 word template/document (.docx)

    I have followed this tutorial.
    How to send the current record to Word 2000 with automation

    However, when I click on "Sent to word" button, something happens.
    I realize it was written for MS Word 97 but I didn't see anything obvious in the code that would cause a problem with word 2010.

    I only used "Name" and "Number" as bookmarks in the word document simply as a starting point to test.

    I also commented out all the photo stuff as I will never need that.

    Here's what I have as it stands. Doesn't throw any errors but nothing happens either.

    Private Sub MergeButton_Click()
        On Error GoTo MergeButton_Err
        Dim objWord As Word.Application
        'Copy the Photo control on the Employees form.
       ' DoCmd.GoToControl "Photo"
        DoCmd****nCommand acCmdCopy
        'Start Microsoft Word 97.
        Set objWord = CreateObject("Word.Application")
        With objWord
            'Make the application visible.
            .Visible = True
            'Open the document.
            .Documents.Open ("C:\Users\Documents\myMerge.docx")
            'Move to each bookmark and insert text from the form.
            .Selection.Text = (CStr(Me.Name))
            .Selection.Text = (CStr(Me.Number))
    '        .ActiveDocument.Bookmarks("Address").Select
    '        .Selection.Text = (CStr(Forms!Employees!Address))
    '        .ActiveDocument.Bookmarks("City").Select
    '        .Selection.Text = (CStr(Forms!Employees!City))
    '        .ActiveDocument.Bookmarks("Region").Select
    '        .Selection.Text = (CStr(Forms!Employees!Region))
    '        .ActiveDocument.Bookmarks("PostalCode").Select
    '        .Selection.Text = (CStr(Forms!Employees!PostalCode))
    '        .ActiveDocument.Bookmarks("Greeting").Select
    '        .Selection.Text = (CStr(Forms!Employees!FirstName))
            'Paste the photo.
    '        .ActiveDocument.Bookmarks("Photo").Select
    '        .Selection.Paste
        End With
        'Print the document in the foreground so Microsoft Word will not close
        'until the document finishes printing.
        objWord.ActiveDocument.PrintOut Background:=False
        'Close the document without saving changes.
        objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
        'Quit Microsoft Word and release the object variable.
        Set objWord = Nothing
        Exit Sub
        'If a field on the form is empty, remove the bookmark text, and
        If Err.Number = 94 Then
            objWord.Selection.Text = ""
            Resume Next
        'If the Photo field is empty.
    '    ElseIf Err.Number = 2046 Then
    '       MsgBox "Please add a photo to this record and try again."
    '    Else
    '        MsgBox Err.Number & vbCr & Err.Description
        End If
        Exit Sub
    End Sub
    Any help is greatly appreciated. Thanks!

    edit: I think i got it figured out. Let me do some testing. Be back with results!
    Last edited by AccessN00b; 07-30-13 at 16:35.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts