The code below is almost complete of course with the help of the members here or on this forum, all is working fine but with one exception it can only send one attachment at a time. I have managed to attach multiple file as you can see below on the screen shoot, so the challenge is how to send them to the recepients
I need help on this part of the below to allow sending multiple files:
Code:
Private Sub Send_btn_Click()
'for early binding, enable tools > References > Microsoft CDO for Windows 2000 Library
Dim Newmail As Object
Dim mailConfig As Object
Dim fields As Variant
Dim msConfigURL As String
Dim varFile As Variant
On Error GoTo Err1:
'late binding
Set Newmail = CreateObject("CDO.Message")
Set mailConfig = CreateObject("CDO.configuration")
mailConfig.Load -1
Set fields = mailConfig.fields
With Newmail
.Sender = DLookup("[EmailAddress]", "[tblSpecialcompanyDetails]", "[CompanyID] = 1")
.From = DLookup("[CompanyName]", "[tblSpecialcompanyDetails]", "[CompanyID] = 1")
.To = Me.SendTo
.Subject = Me.Subject
.TextBody = Me.Message
End With
If Not Attachment = "" Then
With Newmail
.AddAttachment Me.Attachment
End With
End If
If (Me.Cc <> "") Then
With Newmail
.Cc = Me.Cc
End With
End If
msConfigURL = "http://schemas.microsoft.com/cdo/configuration"
With fields
.item(msConfigURL & "/smtpusessl") = True 'enable the SSL authentication
.item(msConfigURL & "/smtpauthenticate") = 1
.item(msConfigURL & "/smtpserver") = "smtp.gmail.com"
.item(msConfigURL & "/smtpserverport") = 465
.item(msConfigURL & "/sendusing") = 2
.item(msConfigURL & "/sendusername") = DLookup("[EmailAddress]", "[tblSpecialcompanyDetails]", "[CompanyID] = 1") 'input your gmail here
.item(msConfigURL & "/sendpassword") = DLookup("[Password]", "[tblSpecialcompanyDetails]", "[CompanyID] = 1")
.Update 'update the configuration fields
End With
Newmail.configuration = mailConfig
Newmail.Send
MsgBox "Your email has been sent.", vbInformation, "Your Email Has Been Sent Successfully"
Me.Status = "Sent"
Exit_Err1:
'release object memory
Set Newmail = Nothing
Set mailConfig = Nothing
Err1:
Select Case Err.Number
Case -2147220973 'due to internet connection
MsgBox "check your internet connection." & vbNewLine & Err.Number & ": " & Err.Description
Case -2147220975 ' due to incorrect credentials
MsgBox "Incorrect Credentials." & vbNewLine & Err.Number & ": " & Err.Description
Case 13 'missing information
MsgBox "Please fill up the required fiels." & vbNewLine & Err.Number & ": " & Err.Description
Case -2146697203 'Invalid link for attachment
MsgBox "Invalid Link for attachment"
Case Else
MsgBox "Error encountered while sending and email.", vbCritical, "Unsend"
End Select
Resume Exit_Err1
On Error Resume Next
End Sub
I need help on this part of the below to allow sending multiple files:
Code:
If Not Attachment = "" Then
With Newmail
.AddAttachment Me.Attachment
End With
End If