Solved

Run word mailmerge from Access

Posted on 2014-02-07
8
878 Views
Last Modified: 2014-05-10
Dear Experts,

As part of a bigger project I need to be able to do the following from Access.

Open up an already prepared word email mailmerge doc and run the mail merge.

Please note the email addresses for the mailmerge is already linked up to the word doc & has nothing to do with the access database.

Can anybody help?
0
Comment
Question by:correlate
  • 3
  • 3
  • 2
8 Comments
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39841270
Albert D. Kallal has a truly great mail merge sample, I'm not sure what exactly you need so this may be a bit of an overkill, but it is definitely worth looking at!

http://www.kallal.ca/wordmerge/index.html
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39841285
If all you want is to open a ready made mailmerge document and execute the merge try this (not tested):

Sub Demo()

   Dim StrFullDocPath As String
   Dim oApp As Object
   
   'Path to the word document
   StrFullDocPath = "C:\Test\TestDocument.docx"
   
   If Dir(StrFullDocPath ) = "" Then
      MsgBox "Document not found."
   Else
      'Create an instance of MS Word
      Set oApp = CreateObject("Word.Application")
      oApp.Visible = True
      
      'Open the Document
      oApp.Documents.Open filename:=StrFullDocPath 
   End If

   With oApp
      With .MailMerge 
         .Destination = wdSendToNewDocument 
         .Execute          
      End With
   End With

   oApp.Close
   Set oApp = Nothing

End Sub

Open in new window

0
 

Author Comment

by:correlate
ID: 39841295
Thanks for this - you code above looks like it will do exactly what I'm after, I have tried it but unfortunately I got an error (438 - Object doesn't support this property or method) - it highlights       With .MailMerge - looking at the code it looks like its trying a document rather than an email mailmerge?

Any ideas
0
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39841364
HI,

pls try

   With oApp
      With ActiveDocument.MailMerge 
         .Destination = wdSendToNewDocument 
         .Execute          
      End With
   End With

Open in new window

Regards
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:correlate
ID: 39841425
HI thanks for that

Alas I'm getting "Object required" pointing to this line ..

      With ActiveDocument.MailMerge
0
 
LVL 27

Accepted Solution

by:
MacroShadow earned 400 total points
ID: 39841490
Try this (once again not tested):

Sub Demo()

    Dim StrFullDocPath As String
    Dim oApp As Object
    Dim oDoc As Object

    'Path to the word document
    StrFullDocPath = "C:\Test\TestDocument.docx"

    If Dir(StrFullDocPath) = "" Then
        MsgBox "Document not found."
    Else
        'Create an instance of MS Word
        Set oApp = CreateObject("Word.Application")
        oApp.Visible = True

        'Open the Document
        Set oDoc = oApp.Documents.Open(FileName:=StrFullDocPath)
    End If

    'Merge to email
    If oDoc.State = wdMainAndSourceAndHeader Or oDoc.State = wdMainAndDataSource Then
        With oDoc.MailMerge
            .Destination = wdSendToEmail
            .Execute
        End With
    End If

    'Clean-up
    oDoc.Close
    oApp.Close
    Set oDoc = Nothing
    Set oApp = Nothing

End Sub

Open in new window

0
 
LVL 49

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 100 total points
ID: 39841493
hi.

forgot the point

With oApp
      With .ActiveDocument.MailMerge 
         .Destination = wdSendToNewDocument 
         .Execute          
      End With
   End With

Open in new window

Regards
0
 

Author Closing Comment

by:correlate
ID: 40055989
Brilliant, thank you for your help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now