We help IT Professionals succeed at work.
Get Started

Multiple Attachments to Email

mtrussell
mtrussell asked
on
486 Views
Last Modified: 2012-05-11
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
Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE