If and Multiple Attachments

beckysright

New member
Local time
Today, 04:19
Joined
May 25, 2012
Messages
4
Hi everyone, I am new to this programming language and I mean really new so please be patient with my lack of knowledge.

I have a form and I have added a checkbox to see what the person wants emailed. I need to be able to send out multiple attachments depending on what check boxes they select. This is the code I have so far.

It is working with just one attachment but not multiple.

Private Sub EmailCapabilities_Click()

Dim objol As Object
Dim objmail As Object
Set objol = CreateObject("Outlook.Application")
Set objmail = objol.createitem(0)
With objmail
.To = "email"
.bcc = "email"
.Subject = "NIS Capabilities Statement"
.Body = "Dear " & FirstName & " " & LastName & ": " & "I have attached the NIS Capabilities Statement, for your convenience. Please feel free to contact me with any questions you may have."
.NoAging = True
If Me.CapStmt = Yes Then
Set objOutlookAttach = .Attachments.Add("C:\Users\Physician Source 4\Documents\personal\NIS Capabilities Statement.pdf")
End If
If Me.CapList = Yes Then
Set objOutlookAttach = .Attachments.Add("C:\Users\Physician Source 4\Documents\personal\NIS Capabilities List.pdf")
End If
If Me.CapMaint = Yes Then
Set objOutlookAttach = .Attachments.Add("C:\Users\Physician Source 4\Documents\personal\NIS Capabilities Maintenance Statement.pdf")
End If
.Display
End With
Set objmail = Nothing
Set objol = Nothing

End Sub

Thank you so much!
 
I have not tested it, as I do not have access, but you are Setting the already assigned object again and again, where it should be just .Attachment.Add, so try the following..
Code:
Private Sub EmailCapabilities_Click()
    Dim objol As Object
    Dim objmail As Object
    Set objol = CreateObject("Outlook.Application")
    Set objmail = objol.createitem(0)
    With objmail
        .To = "email"
        .bcc = "email"
        .Subject = "NIS Capabilities Statement"
        .Body = "Dear " & FirstName & " " & LastName & ": " & "I have attached the NIS Capabilities Statement, for your convenience. Please feel free to contact me with any questions you may have."
        .NoAging = True
        If Me.CapStmt = Yes Then
            .Attachments.Add("C:\Users\Physician Source 4\Documents\personal\NIS Capabilities Statement.pdf")
        End If
        If Me.CapList = Yes Then
            .Attachments.Add("C:\Users\Physician Source 4\Documents\personal\NIS Capabilities List.pdf")
        End If
        If Me.CapMaint = Yes Then
            .Attachments.Add("C:\Users\Physician Source 4\Documents\personal\NIS Capabilities Maintenance Statement.pdf")
        End If
        .Display
    End With
    
    Set objmail = Nothing
    Set objol = Nothing
End Sub
 
Paul,

Thank you so much for replying, I have been hitting refresh forever in the hopes to get this done before I leave work today.

That is allowing me to attach multiple files but if I click on the CapStmt and nothing else it will attach the CapList and the CapMaint but not the Cap Stmt.

Could you help me with that?

Thank you again, you are so awesome!
 
I have always used -1/0 to test checkboxes rather than using Yes/No.. I am sure Yes/No can be used but I would rather stick to constants.. Try that.. see what happens..
 
Have I ever told you how awesome you are? Well you are. Thank you so much. I really appreciate your help.
 
Lol.. Thank you.. I hope I am not too late for getting into Santa's list of 'Nice'... Good luck.. :)
 

Users who are viewing this thread

Back
Top Bottom