Avatar of mtrussell
mtrussell

asked on 

Multiple Attachments to Email

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


MyMail.Display
End Sub
Microsoft Access

Avatar of undefined
Last Comment
mtrussell

8/22/2022 - Mon