Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


I need help emailing letters to individual email addresses

Posted on 2010-08-12
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
LVL 93

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 500 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 500 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.



Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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...


LVL 31

Assisted Solution

by:Helen Feddema
Helen Feddema earned 500 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

by:Helen Feddema
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 500 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, http://www.fmsinc.com/MicrosoftAccess/Email.asp, 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 93

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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

610 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