Issues with Code to Send attachments (1 Viewer)

tucker61

Registered User.
Local time
Today, 10:37
Joined
Jan 13, 2008
Messages
321
I have the following code which seems to have worked for ages, is all of a sudden giving me a issue.

the code runs ok, but i get the message saying that the file has failed adding the attachment, check if it exists. Even though i know the attachments exist.

In total there are 30 attachments that need to be added (is this too many) and all of the attachments i have noticed are over 2mb.

So the first 17 attachments get added to the email, but anything after that i get the msbox....

I deleted the first 17 attachments from the server, and then the rest attached with no problems, so is their a limitation on the number of attachments, or the size of the attachments ?

I have just compressed the first 10 pictures and then this code ran with no problems at all.

Code:
Public Sub OutlookEmail(tolist As String, cclist As String, SubjectLine As String, Message As String, AttachmentPaths As Variant, Optional ShowMessage As Boolean)
On Error GoTo Handler
Dim strEmail As String
Dim strMsg As String
Dim oLook As Object
Dim oMail As Object
Dim i As Integer
    SnoozeReminders
    Set oLook = CreateObject("Outlook.Application")
    Set oMail = oLook.CreateItem(0)
    With oMail
        .To = tolist
        .cc = cclist
        .Subject = SubjectLine
        .Body = Message
        
        i = 0
        While Not AttachmentPaths(i) = vbNullString
            On Error Resume Next
            .Attachments.Add (AttachmentPaths(i))
            If Err <> 0 Then
                MsgBox "The attachment . . ." & vbNewLine & "'" & AttachmentPaths(i) & "'" & vbNewLine & "has failed - please check it exists!", vbExclamation + vbOKOnly, "Not Found"
                Err.Clear
            End If
            On Error GoTo 0
            i = i + 1
        Wend
        If ShowMessage Then
            .Display
        Else
            .send
        End If
    End With
    Set oMail = Nothing
    Set oLook = Nothing
Exit Sub
Handler:
        Call LogError(Err.Number, Err.Description, "Outlook  Email", Forms!frmmain.tbJobID)
        Exit Sub

End Sub

also - can someone please explain how this code works
Code:
       If ShowMessage Then
            .Display
        Else
            .send
end if

Thanks.
 

Ranman256

Well-known member
Local time
Today, 13:37
Joined
Apr 9, 2015
Messages
4,337
your email may have a limit on attachements.

.display will only show you the email without sending (review)

.send , does that, sends the email.
 

Users who are viewing this thread

Top Bottom