Email personalised Word attachment to list of recipients

mcjj

New member
Local time
Today, 17:31
Joined
Feb 8, 2013
Messages
1
I have an Access 2003 db containing employee details including name and email address. Based on a query, I need to send an email (Outlook 2003) with a Word attachment (a certificate) to certain employees. I need to include on the certificate the employee's name and other information from the query. Based on examples found on forums I have been able to send emails with a Word attachment but I have not been able to include the recipent's name in it. I have tried using a Word mailmerge but have not been successful. I don't have much VB experience so any help with this problem would be much appreciated.​
 
This works in 2007. Might need some tweaks to work in 2003.

First, you need to put a "Content Control" in your word doc. Open your document, click on the developer tab, select rich text, then enter the name for the field (i.e. FullName).

Then, in Access, you need to reference the Microsoft Word Object Library.

Then, insert code like this (DocPath is a string containing the path for the word document and DocName is a string containing the name):

Code:
Dim WordApp as Word.Application
Dim doc as Word.Document
Dim fld as Word.ContentControl

'Open Word document
Set WordApp = New Word.Application
WordApp.Documents.Open DocPath
Set doc = WordApp.ActiveDocument
WordApp.Visible = True

'Loop through all content controls (written to handle multiple controls)
'If you add more controls, just add more Case statements
For Each fld in doc.ContentControls
     Select Case fld.range.text
          Case "FullName"
               fld.range.text = DocName
     End Select
Next

'Save document
doc.Save

Then proceed as you normally do to attach and email the document.

Questions?
 

Users who are viewing this thread

Back
Top Bottom