To use MS Access to send an email to one or all users from a specified list, with the option to include an attachment, follow these steps:
Sub SendEmailWithAttachment()
Dim oApp As Object
Dim oMail As Object
Dim strRecipients As String
Dim strSubject As String
Dim strBody As String
Dim strAttachmentPath As String
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
'Set recipients
strRecipients = "user1@example.com; user2@example.com"
oMail.To = strRecipients
'Set subject and body
strSubject = "Your email subject"
strBody = "Your email body"
oMail.Subject = strSubject
oMail.Body = strBody
'Add attachment
strAttachmentPath = "C:\path\to\file.jpg"
If strAttachmentPath <> "" Then
oMail.Attachments.Add (strAttachmentPath)
End If
'Send email
oMail.Send
Set oMail = Nothing
Set oApp = Nothing
End Sub
Modify the code to include your specific recipients, subject, body, and attachment path.
Call the SendEmailWithAttachment() subroutine from your Access form or report.
When the subroutine is executed, an Outlook email message will be created with the specified recipients, subject, and body. If an attachment path is provided, it will also be attached to the email. The email will be sent when oMail.Send is called.
Note: This code requires that Outlook is installed on the computer and that the Outlook security settings allow programmatic access to send emails. If you encounter security warnings or errors, you may need to modify your Outlook settings or use a third-party email component.
Asked: 2023-05-17 00:00:55 +0000
Seen: 11 times
Last updated: May 17 '23