I have configured the Gmail in MS Access 2016 with VBA and everything is work okay:
(1) I'm able to select recipients emails from the combo box
(2) I'm able to concatenate several emails automatically like we do it in outlook
(3) I have made both the attachment and CC as option all is working okay
Issues require your help
(1) I have this error after successfully succeeded sending an e mail : "execution this software stopped due to run time error"
(2) How to attach more than one attachment , is it possible
VBA Code used see below:
Both the error message and the VBA referencing is shown above, please note that the error does not affect the delivery of emails to the recipients, but I need to suppress that error
(1) I'm able to select recipients emails from the combo box
(2) I'm able to concatenate several emails automatically like we do it in outlook
(3) I have made both the attachment and CC as option all is working okay
Issues require your help
(1) I have this error after successfully succeeded sending an e mail : "execution this software stopped due to run time error"
(2) How to attach more than one attachment , is it possible
VBA Code used see below:
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
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
End
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
Both the error message and the VBA referencing is shown above, please note that the error does not affect the delivery of emails to the recipients, but I need to suppress that error