Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Adding multiple attachments in automated email from MS Access to MS Outlook

Posted on 2016-10-25
3
Medium Priority
?
50 Views
Last Modified: 2016-11-16
Please help, all I want to do is to add code that would allow me to attach files from network specific locations. The code below works to attach the  XH-772_4_Circulation report from Access using the DoCmd.SendObject, but I also want to attach the file at the network location: \\BORG\UserShar\Nadcap\Operator Training\Current Procedures\PE-4014.pdf

Public Function sendEmail()
Dim MyDB As DAO.Database
Dim rstEmail As DAO.Recordset
Dim rstCcEmail As DAO.Recordset
Dim strBuild As String
Dim strSQL As String
Dim strCcSQL As String
Dim strmgrBuild As String

Set MyDB = CurrentDb

strSQL = "SELECT Supervisor_Name " & _
"FROM Due_Supervisor_Email;"

strCcSQL = "SELECT Member " & _
"FROM Due_Member_Email;"

Set rstEmail = MyDB.OpenRecordset(strSQL, dbOpenForwardOnly)
Set rstCcEmail = MyDB.OpenRecordset(strCcSQL, dbOpenForwardOnly)

With rstEmail
Do While Not .EOF
strBuild = strBuild & ![Supervisor_Name] & ";"
.MoveNext
Loop
End With

strmgrBuild = strBuild + "jspenc@gmail.com"

With rstCcEmail
Do While Not .EOF
strCcBuild = strCcBuild & ![Member] & ";"
.MoveNext
Loop
End With

DoCmd.SendObject acSendReport, "XH-772_4_Circulation", "PDF", strmgrBuild, strCcBuild, "jeff.spencer@gmail.com", "Due Training"

' File location that I want attached: \\BORG\UserShar\Nadcap\Operator Training\Current Procedures\PE-4014.pdf

rstEmail.Close
Set rstEmail = Nothing

End Function
0
Comment
Question by:jaspence
[X]
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
3 Comments
 
LVL 85

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1000 total points (awarded by participants)
ID: 41858943
You can't attach external items using the SendObject method. You'll have to use automation for that. Here's an EE article that shows how, along with a sample database:

https://www.experts-exchange.com/articles/4316/Automate-Outlook-in-VBA-with-the-OutlookCreateItem-Class.html
0
 
LVL 31

Accepted Solution

by:
Helen Feddema earned 1000 total points (awarded by participants)
ID: 41863942
You need the file name, not just the path (unless you want to iterate through a folder, and attach all files -- let me know if you need code for that).  Here is some code to attach a single attachment to an outgoing email:

Private Sub SendMailAttachment
'Created by Helen Feddema 5-19-2000
'Last modified 16-May-2010

On Error GoTo ErrorHandler

   Dim appOutlook As New Outlook.Application
   Dim msg As Outlook.MailItem
   Dim strFileName As String
   Dim strFilePath As String
   
   strFilePath = Application.CurrentProject.Path
   strFileName = strFilePath & "\Contacts.csv"
   
   'Save Contacts table as a text file in same folder as database
   DoCmd.TransferText acExportDelim, "Contacts Export Specification", _
      "tblContacts", strFileName, True
      
   'Create new mail message and attach text file to it
   Set msg = appOutlook.CreateItem(olMailItem)
   With msg
      .To = "John Doe"
      .Subject = "Contacts file you requested"
      .Body = "This file was exported from tblContacts on " & _
         Date & "." & vbCrLf & vbCrLf
      .Attachments.Add strFileName
      .Display
   End With
   
ErrorHandlerExit:
   Exit Sub

ErrorHandler:
   MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
   Resume ErrorHandlerExit

End Sub

Open in new window

0
 
LVL 85
ID: 41889421
Helen's comment included code to resolve the issue, and mine included a link to an EE article that also provided a sample database.
0

Featured Post

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.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

688 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