Link to home
Start Free TrialLog in
Avatar of SteveL13
SteveL13Flag for United States of America

asked on

Trying to add multiple files to an email message

I am using the following code in an attempt to attach multiple files to an email.  In some cases there may be just one file to attach but in other cases more than one.  The code as it exists right now only sends the first file even if there are two files to be send.  It needs to send both files in the email if there are more than one.

    strAttachment = Me.txtCastingPrintsDataPath   'strAttachment is the path to the attachments
    
    For j = 1 To 5
    filename = Dir(strAttachment)
        If Me("chkbxPatternSource" & j) = True Then
            Set objMail = olApp.CreateItem(olMailItem)
            strEmail = Me("txtPatternSourceEmail" & j) & ";"
            With objMail
                .To = strEmail
                .Subject = strSubject
                .HTMLBody = strHTMLBody
                .Attachments.Add strAttachment & filename
                .Send
            End With
        End If
    Next

    Set objMail = Nothing
    Set olApp = Nothing
    
    End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SteveL13

ASKER

Nice!  Thanks.