Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.