Results 1 to 2 of 2
  1. #1
    Lounger
    Join Date
    Sep 2001
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA to mailmerge and finalize (Access 07/Word 07)

    I have been asked to make one button to merge reporting information into the word document provided. The merge and query work correctly when doing it manually and I am trying to automate the function to produce the report without me being involved. I am to a point now where it will run the document bu it stops as it brings up the OpenDataSource command. My goal is to get to the finalized merge of all records. Any suggestions would help. The code is as follows:

    Private Sub Command3_Click()
    On Error GoTo Err_Command3_Click
    'Load the mail merge document as an object
    Dim objWord As Object
    Set objWord = GetObject("I:Report Merge.doc", "Word.Document")
    'Make Word visible
    objWord.Application.Visible = True
    'Open the mail merge data source (this database and record)
    objWord.MailMerge.OpenDataSource _
    Name:="I:database.mdb", _
    LinkToSource:=True, _
    Connection:="Query QRY_Report", _
    SQLStatement:="SELECT * FROM [Update]"

    'Execute the mail merge
    objWord.MailMerge.Execute

    Exit_Command3_Click:
    Exit Sub

    Err_Command3_Click:
    MsgBox Err.Description
    Resume Exit_Command3_Click
    End Sub

  2. #2
    Lounger
    Join Date
    Sep 2001
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA to mailmerge and finalize (Access 07/Word 07)

    I think I have it working now once I put it in I saw that this statement should have read: SQLStatement:="SELECT * FROM [QRY_Update]"

    Thanks

Posting Permissions

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