troubleshooting Question

Multiple Attachments to Email

Avatar of mtrussell
mtrussell asked on
Microsoft Access
6 Comments1 Solution488 ViewsLast Modified:
I have a table called Tbl_TaggedFiles with a column called dockey which is the file name of files on the network.  I have the functionality to add an attachment (see below) for one file but what I would like to do is loop through the entire table and attach all the file names which are in the table.  There are a lot of examples out there but whenever I add a few lines to make it work I keep tripping up somewhere and would appreciate some help.  Below is the code which works to add one file.  How do I get all file names to attach to an Outlook email?   I also would appreciate the code to look and see if the table is empty and if so it sends up a message box but I can sort this later too.  

Public Sub sendfile2()

Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim objOutlook As Object
Dim Attach As String
Dim doc As DAO.Recordset
Dim db  As DAO.Database
Dim docname As String

   Set db = CurrentDb
   Set doc = db.OpenRecordset("tbl_taggedfiles")
   docname = doc("dockey").value
'Check if outlook if open
Set objOutlook = GetObject(, "Outlook.Application")
    On Error GoTo 0

Set MyOutlook = New Outlook.Application
Set MyMail = MyOutlook.CreateItem(olMailItem)

Attach = "\\jassrv03\jas-fp$\Documents\" & docname 'c
MyMail.Attachments.Add Attach

End Sub

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros