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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy and Paste in Word Mailmerge Document from Access VBA 1

Status
Not open for further replies.

GaryCanuck

Technical User
Feb 17, 2007
24
CA
Hi All,
I'm currently using both Word and Access 2007. I want to insert a table of selected values into a mailmerge letter. If I enter the fields in and hit run then I get an individual letter for each record. However if the table is a separate document then it merges continuously as desired. So what I am aiming to do is merge the table, merge the letter and then copy and paste the table into the letter from access vba. When I run the code (from button) I get an extra version of word running and a message saying the remote server is unavailable. I'm lead to believe this is due to improperly sourcing, identifying variables, etc. Any ideas where it's going astray? Here is my most recent attempt:

Code:
DoCmd.SetWarnings False
    DoCmd.OpenQuery "Notice of Public Auction"
    DoCmd.SetWarnings True
                
                Dim db As Database
                Set db = OpenDatabase("\\Taxerver\taxervice\Access\TaxSale_be.mdb")
                                
        Dim objWord As Word.Document

        Set objWord = GetObject("\\Taxerver\taxervice\Templates\Public Auction Table.docx", "Word.Document")

        objWord.Application.Visible = False
        objWord.MailMerge.Execute
        Selection.WholeStory
        Selection.Copy
        objWord.Close False
        
        Dim oWord As Word.Document
        Set oWord = GetObject("\\Taxerver\taxervice\Templates\Notice of Public Auction.docx", "Word.Document")
        
        oWord.Application.Visible = True
        oWord.MailMerge.Execute
        oWord.Close False
        
        Dim pWord As Word.Document
        Set pWord = Word.ActiveDocument
        pWord.Application.Visible = True
        pWord.ActiveDocument.Bookmarks("Table2").Select
        Selection.Paste

Any help is always appreciated, thanks in advance,
Tyler
 
You have to use full qualified objects, eg:
objWord.Application.Selection.WholeStory

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top