Yes. In Microsoft Access for Windows, VBA can create an email in classic Outlook, add a file with the Outlook Attachments.Add method, and send it with .Send. The example below uses late binding, so it does not require you to add an Outlook reference in the VBA editor.
How Access VBA sends an attached email
Access does not send a file directly through the Outlook object model. Instead, VBA asks Outlook to create a message, fills in its fields, adds the file, and either displays or sends the message. Outlook then handles the message through the mail account configured in its profile. This is useful when an Access form, report, or database process needs to email a document without asking the user to compose the message from scratch.
The code uses Outlook automation, also called COM automation. It is intended for Access running on Windows with classic Outlook for Windows installed and configured. Microsoft’s new Outlook for Windows does not support the same COM automation model, so this example is not a solution for new Outlook. Access desktop is not available for macOS, either; a Mac user would need a different application or service to send mail.
Working VBA example
Put this procedure in a standard Access VBA module. Change the recipient, subject, message, and attachment path to suit your database. It checks that the file exists before asking Outlook to attach it. The message is sent immediately; change .Send to .Display if you want Outlook to open a draft for review instead.
Public Sub SendAccessEmailWithAttachment()
Dim olApp As Object
Dim olMail As Object
Dim attachmentPath As String
On Error GoTo ErrHandler
' Use a full path to the file to attach.
attachmentPath = "C:\Reports\MonthlySummary.pdf"
If Len(Dir$(attachmentPath)) = 0 Then
MsgBox "Attachment not found: " & attachmentPath, vbExclamation
GoTo CleanExit
End If
' Late binding avoids a required Outlook reference.
Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(0) ' 0 = Outlook mail item
With olMail
.To = "recipient@example.com"
.CC = ""
.Subject = "Monthly summary"
.Body = "Hello," & vbCrLf & vbCrLf & _
"Please see the attached monthly summary." & vbCrLf
.Attachments.Add attachmentPath
.Send
' Use .Display instead of .Send to review the message first.
End With
MsgBox "Outlook accepted the message for sending.", vbInformation
CleanExit:
Set olMail = Nothing
Set olApp = Nothing
Exit Sub
ErrHandler:
MsgBox "The email could not be sent: " & Err.Description, vbExclamation
Resume CleanExit
End Sub
The message uses plain text through .Body. For a formatted HTML message, assign the markup to .HTMLBody instead; do not expect .Body to interpret HTML tags. If you use both properties, set the HTML body deliberately and avoid relying on an order of assignments to preserve formatting.
Set up the database and Outlook
Before running the procedure, make sure classic Outlook is installed, has a working mail profile, and can send mail manually. The code uses the default Outlook profile, so it does not select a particular account. If a computer has several mail accounts, confirm which account Outlook uses as its default or extend the automation to select a sending account.
- Save the Access database in a trusted, backed-up location and enable its VBA code only if you trust the database.
- Replace the sample path with a complete path, such as
C:\Users\Ari\Documents\Report.pdf. A path to a mapped drive may not be available when Access runs under another Windows account or scheduled process. - Use a real recipient address and test first with an address you control. Separate multiple recipients in Outlook’s recipient fields with semicolons.
- Ensure the Windows account running Access has permission to read the attachment and use Outlook’s configured profile.
To create the procedure, open the Access database, press Alt+F11 to open the Visual Basic Editor, and choose Insert > Module. Paste the code, edit the values, and run the procedure from the editor or call it from a form button. In the editor, choose Debug > Compile before running if you have made other code changes. Access VBA macros and procedures can change data or send messages, and their actions cannot be undone with Ctrl+Z. Save a separate copy of the Access database before running unfamiliar or modified automation.
Attach a file generated from an Access report
A common workflow is to export a report to PDF and attach that PDF. The attachment must exist at the path supplied to .Attachments.Add before the message is created or sent. For example, you can use Access’s DoCmd.OutputTo to export a report to a known temporary or output folder, then pass that same full path to the email procedure. Choose a unique filename if several users might run the process at the same time; otherwise one run could overwrite another run’s file.
When exporting a report for a particular customer or date range, make sure the report is filtered to the intended records before exporting. A report that opens correctly on screen is not automatically proof that the exported attachment contains only the intended data. Check the PDF itself during testing, especially if the database uses forms, report filters, or criteria entered by a user.
You can also attach an existing file selected by the user, but validate the selected path before sending. Avoid constructing a path from untrusted input without checking it. For a file stored on a network share, confirm that the recipient process and the Access user both have appropriate access; attaching it embeds a copy in the email, while inserting a path into the message does not.
Sending immediately versus displaying a draft
.Send tells Outlook to submit the message through the configured profile. It does not prove that the recipient received it: Outlook may place the message in the Outbox while offline, and delivery can still fail later. A success message from Access should therefore be understood as “the send request ran,” not as a delivery receipt.
Using .Display is usually safer while developing. It opens the message so a person can inspect the recipient, subject, body, and attachment, then click Send in Outlook. Once the process has been checked and the business case genuinely calls for unattended sending, you can decide whether to use .Send. Consider adding logging to the database for the record ID, timestamp, attachment path, and any error returned, but do not log sensitive message contents unnecessarily.
Security, privacy, and attachment size
Emailing a file can disclose information outside the database, so check that the recipient is correct and that the attachment is appropriate to send. A file created from a report might contain more records or personal details than the message recipient needs. If the attachment is confidential, follow your organization’s approved encryption, retention, and transfer rules rather than assuming that ordinary email is secure enough.
Outlook or an organization’s security configuration may warn about programmatic sending or block it. Behavior depends on the Outlook version, security settings, antivirus status, and administrative policies. Do not disable Outlook security controls or install an untrusted tool merely to suppress a warning. Ask the Microsoft 365 or IT administrator which approved approach is available for the organization.
Mailbox and recipient systems can also impose message-size limits. The effective limit may be lower than the attachment’s raw file size because email encoding adds overhead, and limits vary by organization and mail service. For large files, use an approved SharePoint, OneDrive, or other managed sharing link where appropriate instead of attaching a bulky file. Confirm that the intended recipients will have permission to open the shared file.
Common problems and practical fixes
- “Attachment not found”: Check spelling, the extension, and the full path. Use
Dir$(attachmentPath)as in the example, and verify that the file is present at send time. - Outlook cannot be created: Confirm that classic Outlook is installed and configured, and that the code is running in the expected Windows user session. New Outlook does not provide the COM interface this example uses.
- The email is not delivered: Check Outlook’s Outbox and Sent Items, connectivity, account status, and any returned delivery failure. The VBA procedure cannot guarantee delivery to an external mailbox.
- A security warning appears: Treat it as a security or policy issue, not simply a coding defect. Consult the organization’s administrator rather than weakening protection.
- The wrong account sends it: The sample uses Outlook’s default profile behavior. Confirm the default sending account or add account-selection logic appropriate to the installed Outlook version and profile.
- The recipient gets the wrong report: Inspect the exported file before sending and verify report filters and criteria. A valid attachment path does not validate the file’s contents.
For troubleshooting, temporarily switch to .Display, then inspect the draft and the attachment before sending manually. You can also add diagnostic messages around export and attachment steps. Avoid showing passwords or storing them in VBA; Outlook should use its configured authentication and organizational sign-in mechanisms.
Outlook automation compared with Access SendObject
Access also has the DoCmd.SendObject method. It is convenient for emailing an Access object, such as a report or query, in a supported output format. It is not the same as the Outlook Attachments.Add method: SendObject is designed to send an Access object, rather than attach any arbitrary file path you choose. Use Outlook automation when you need to attach an existing PDF, image, spreadsheet, or other file and control the message fields through Outlook.
Both approaches depend on the available mail setup and organizational policy, and neither should be treated as a guarantee of delivery. Outlook automation offers more control over a message and attachment, but it also ties the process to classic Outlook on Windows. For a process that must run on a server or without a desktop Outlook profile, investigate an organization-approved mail API or service instead. Such options require appropriate authentication, permissions, and administrator approval; they are not drop-in replacements for this short VBA procedure.
Frequently Asked Questions
Can Access VBA attach a PDF to an email?
Yes. If the PDF exists and the Access user can read it, Outlook automation can add it with Attachments.Add. Export an Access report to PDF first if the PDF needs to be generated from database data.
Does this code work with the new Outlook for Windows?
No, not through the classic Outlook COM automation shown here. Use classic Outlook for Windows with a configured profile, or choose an approved alternative such as an email API for a workflow that cannot depend on classic Outlook.
Can I preview the email before it is sent?
Yes. Replace .Send with .Display. Outlook opens the composed message, allowing a person to check its details and send it manually.
Can I attach a report without saving it as a file?DoCmd.SendObject can send an Access report as an output attachment in a supported format. If you need to attach a specific file path or control Outlook’s message more directly, export the report to a file and use Outlook automation.
Can Access send the email without Outlook installed?
Not with this Outlook automation example. It creates the message through Outlook’s Windows COM interface. A different mail service or API may send messages without desktop Outlook, but setup, authentication, and permissions depend on that service and the organization’s policies.
Related
- What Is Power Query? Excel Data Cleanup Explained
- AI and Power Query: What It Can and Cannot Do in Excel
- Power Query Split Cell Into Rows: Steps and Examples
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA: Check Whether a Worksheet Name Exists SafelyTo check whether a worksheet exists in Excel VBA, try to assign the named item from the target…
- Can Google Sheets Run Macros? A Guide to How They WorkYes. Google Sheets can run macros: you can record a sequence of spreadsheet actions, save it, and run…
- VBA InputBox Cancel: Detecting Cancel and Blank RepliesIn VBA, the built-in InputBox function returns an empty string when the user clicks Cancel, but it also…
- Excel VBA Button: Add, Assign, and Fix Macro ButtonsAn Excel VBA button is a clickable control that runs a macro in a workbook. In Excel for…
- VBA: Clear an AutoFilter If It Exists SafelyYes. In Excel VBA, check whether the worksheet is currently filtered with Worksheet.FilterMode, then call ShowAllData only when…
- Fortify Macro Recorder: Does Fortify Record Macros?No: OpenText Fortify is an application-security product family, not a macro recorder, and its standard tools do not…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.