I need help emailing letters to individual email addresses

Posted on 2010-08-12
Last Modified: 2013-11-28
I need to preface this message by saying that while I have a lot of experience creating databases and working with macros, I have next to no experience with VB coding so any help I receive I really need specific help doing what I need to.Basically, I have a database where I run a report that is basically an hours status letter that runs for customers based on some criteria of number of hours remaining and activity in a month.  The result is a report that contains several letters, one for each customer and I am currently printing the entire report, parsing out each customer's report and mailing it.What I would like is an automated way to generate each customer's letter and email is a pdf attachment.  I have gone through various other threads and have seen references to recordsets and looping but due to my novice status, I am unable to figure out how to apply this information to my database and integrate it in. I understand this is a novice question and that anybody who responds will need to give me some handholding to walk me through how to get this code in and how to customize it with my database.  Thanks very much, any help is greatly appreciated.
Question by:nomi1
  • 2
  • 2
  • 2
  • +2
LVL 92

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 125 total points
ID: 33424663
Without going into a ton of detail, this sounds like the sort of thing Word's Mail Merge was made for.  Word is content to use Access as the data source and Outlook as the delivery mode for a Mail Merge.
LVL 10

Expert Comment

ID: 33425326

When you get a chance checkout this article, you can probably skip the first portion of it since you said you have been creating DBs for  while now.  But i may be a good starter for you see how and where the VBA portions start to come into it.

LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 125 total points
ID: 33425635
The thing here is that you cannot simply Email a report, you have to specify a format
(RTF, XLS, PDF, ...ect)

You did not specify your version of Access.
The is important because, in order to create a PDF, you will need an External utility for Access 2003 and older.
You will need to PDF Addin installed for Access 2007 and newer.

Here is a sample of both:
Access 2003 an older, PDF and RTF
Access 2007 PDF and rtf

I am sure with your experience you will be able to read through the code and tweak/troubleshoot it to work in your database.



LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 33425676

I just read the expert post.

Yes, if you have not the Skills to use VBA, then the Word route might be an easier option.
So give that a try first.

If you plan on posting more questions here requiring code solutions, then you should pick up a good reference book.
Here are a few:

You can goole for more...


Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

LVL 31

Assisted Solution

Helen_Feddema earned 125 total points
ID: 33438219
Here is some code to save filtered reports as PDFs and email each to the appropriate address:
Option Compare Database

Option Explicit

Private dbs As DAO.Database

Private qdf As DAO.QueryDef

Private rst As DAO.Recordset

Public Sub SendInterventionEmails()

'Created by Helen Feddema 10-Jan-2010

'Last modified by Helen Feddema 10-Jan-2010

On Error GoTo ErrorHandler

   Dim appOutlook As New Outlook.Application

   Dim itm As Outlook.MailItem

   Dim rstIntervention As DAO.Recordset

   Dim lngCount As Long

   Dim lngID As Long

   Dim rpt As Access.Report

   Dim strFileName As String

   Dim strPrompt As String

   Dim strQuery As String

   Dim strRecordSource As String

   Dim strReport As String

   Dim strSQL As String

   Dim strTitle As String

   Dim strCurrentPath As String

   Dim strFileNameAndPath As String

   Dim strEmailSource As String


   strEmailSource = "qryInterventionEmail"

   strRecordSource = "qryMissingAssignments"

   strQuery = "qryMissingAssignmentsSingleStudent"

   Set dbs = CurrentDb

   Set rstIntervention = dbs.OpenRecordset(strEmailSource)

   strCurrentPath = Application.CurrentProject.Path & "\"


   'Use path selected with SelectFolder procedure

   'strCurrentPath = SelectFolder()

   With rstIntervention

      Do While Not .EOF

         lngID = ![StID]

         Debug.Print "Processing Student ID " & lngID

         strFileName = "Intervention Report for " & ![StFirst] _

            & " " & ![StLast] & ".pdf"

         strFileNameAndPath = strCurrentPath & strFileName


         'Create filtered query

         strSQL = "SELECT * FROM " & strRecordSource & " WHERE " _

            & "[StID] = " & Chr(39) & lngID & Chr(39) & ";"

         Debug.Print "SQL for " & strQuery & ": " & strSQL

         lngCount = CreateAndTestQuery(strQuery, strSQL)

         Debug.Print "No. of items found: " & lngCount

         If lngCount = 0 Then

            GoTo NextStudent

         End If


         'Open report with filtered query record source

         strReport = "rptMissingAssignmentsNew"

         DoCmd.OpenReport ReportName:=strReport, _

            View:=acViewPreview, _


         Set rpt = Reports(strReport)

         DoCmd.OutputTo objecttype:=acOutputReport, _

            objectname:=strReport, _

            outputformat:=acFormatPDF, _



         'Create email

         Set itm = appOutlook.CreateItem(olMailItem)

         itm.Subject = "MISSING WORK"

         itm.Body = "The attached file lists your missing assignments"

         itm.To = ![Email]

         itm.Attachments.Add Source:=strFileNameAndPath, _



         'For editing before sending



         'For sending automatically


         DoCmd.Close objecttype:=acReport, _

            objectname:=strReport, _





   End With



   Exit Sub


   MsgBox "Error No: " & Err.Number _

      & " in SendInterventionEmails procedure; " _

      & "Description: " & Err.Description

   Resume ErrorHandlerExit

End Sub

Public Function CreateAndTestQuery(strTestQuery As String, _

   strTestSQL As String) As Long

'Created by Helen Feddema 28-Jul-2002

'Last modified by Helen Feddema 10-Jan-2010

On Error Resume Next


   'Delete old query

   Set dbs = CurrentDb

   dbs.QueryDefs.Delete strTestQuery

On Error GoTo ErrorHandler


   'Create new query

   Set qdf = dbs.CreateQueryDef(strTestQuery, strTestSQL)


   'Test whether there are any records

   Set rst = dbs.OpenRecordset(strTestQuery)

   With rst



      CreateAndTestQuery = .RecordCount

   End With



   Exit Function


   If Err.Number = 3021 Then

      CreateAndTestQuery = 0

      Resume ErrorHandlerExit


   MsgBox "Error No: " & Err.Number _

      & " in CreateAndTestQuery procedure; " _

      & "Description: " & Err.Description

   End If


End Function

Open in new window

LVL 31

Expert Comment

ID: 33438229
My ebook Working with Word may also be helpful.  It updates some of the examples in my Access 2007 VBA Bible book, and adds some new examples.
LVL 10

Accepted Solution

Luke Chung earned 125 total points
ID: 33582946
If you're not a coder and want to use a solution that runs as an Access add-in, our Total Access Emailer program,, will do what you seek.

Total Access Emailer will take a table with a list of email addresses and let you filter reports based on values in your table to send emails with PDF reports specifically for each contact.

Your messages can be in text or HTML. The HTML messages can include embedded graphics, and the messages can automatically use fields from your table so each message and subject can be personalized.

Best of all, you don't need to do any programming for all of these features.

A free demo is available for you to try it out.  Good luck.
LVL 92

Expert Comment

by:Patrick Matthews
ID: 36157638
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

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

Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

919 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

12 Experts available now in Live!

Get 1:1 Help Now