Ask Your Question
1

How can I use MS ACCESS to send an email to one or all users from a specified list, with the option to include an attachment?

asked 2023-05-17 00:00:55 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-17 00:14:02 +0000

scrum gravatar image

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:

  1. Create a new module in MS Access and add the following code:

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

  1. Modify the code to include your specific recipients, subject, body, and attachment path.

  2. Call the SendEmailWithAttachment() subroutine from your Access form or report.

  3. 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.

edit flag offensive delete link more

Your Answer

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

Add Answer


Question Tools

Stats

Asked: 2023-05-17 00:00:55 +0000

Seen: 11 times

Last updated: May 17 '23