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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-17 00:00:55 +0000
Seen: 11 times
Last updated: May 17 '23
What is the method to locally access Files with JCIFS?
How to access HTML files stored on Google Drive?
How can several goroutines access a shared channel for reading data?
What is the appropriate response from the backend when a JWT token has expired?
What is the issue when navigating from a child fragment to a bottom navigation fragment?