Hi @Mark Powell
Thank you for reaching out to the Microsoft Q&A Forum.
Based on your description, I tried creating a basic setup and tested it on my side, and it worked for me. You can refer to the steps below:
1.Create a simple table, build a query to summarize the data, and then create a report based on that query.
2.Add a command button to a form.
3.Run the following VBA code to export the report as a PDF and send it via Outlook:
Private Sub Command0_Click()
On Error GoTo ErrHandler
Dim rptName As String
Dim pdfPath As String
Dim olApp As Object
Dim olMail As Object
rptName = "rptSalesSummary"
pdfPath = Environ$("TEMP") & "\" & rptName & "_" & Format(Now, "yyyymmdd_hhnnss") & ".pdf"
DoCmd.OutputTo acOutputReport, rptName, acFormatPDF, pdfPath, False
Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(0)
With olMail
.To = "enter_recipient_email_here"
.Subject = "Sales Report (PDF)"
.Body = "Hello," & vbCrLf & vbCrLf & _
"Please find the attached PDF report." & vbCrLf & vbCrLf & _
"Best regards."
.Attachments.Add pdfPath
.Send
End With
Cleanup:
Set olMail = Nothing
Set olApp = Nothing
Exit Sub
ErrHandler:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation
Resume Cleanup
End Sub
Could you let me know if this is what you were hoping to achieve? If so, please adjust the code and steps to fit your setup.
I hope this helps.
If the answer is partially helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.