How to send a report using VBA via outlook 2010 issues (1 Viewer)

fearmichaele

Registered User.
Local time
Today, 09:35
Joined
Jan 14, 2014
Messages
34
I have a VBA module in my Access 2010 database that will send a report as a PDF via email to a predetermined email address. the only problem using the docmd.sendobject method is i keep getting a pop up that says "A program is trying to send an e-mail on your behalf. If this is unexpected, click Deny and verify your antivirus software is up-to-date."

I have a windows task set up at the same time each day to open this database which runs an autoexec that creates this report and using my VBA module sends the email. i want it to just send the email without any imput from me. I want automation. Any help would be greatly appreciated.

here is my code that i am using to create and send the email

"Private Sub Report_Activate()

filename = "Name of file" & Format(Me.Date_time_returned "MMDDYY") & ".pdf"

DoCmd.SetWarnings False

DoCmd.SendObject acSendReport, "Name of file", acFormatPDF, "the destination email address goes here",,, "Request completed and sent " & Format(Me.Date_time_returned, "MMDDYY"), "Subject of email goes here", False

DoCmd.SetWarnings True

End Sub"
 

AOB

Registered User.
Local time
Today, 15:35
Joined
Sep 26, 2012
Messages
560
The warning is there for good reason - to prevent spam and unwanted automated e-mails. The warning is driven by Outlook, not Access.

Try this article, it may help...
 

AOB

Registered User.
Local time
Today, 15:35
Joined
Sep 26, 2012
Messages
560
Or this...
 

fearmichaele

Registered User.
Local time
Today, 09:35
Joined
Jan 14, 2014
Messages
34
thanks. i was able to modify my code using the example of the first article. my code works and ended up looking like this for any other users haveing the same issue.

filename = "name of file i created with my report to be emailed."

Dim outl As Outlook.Application

Set outl = New Outlook.Application

DoCmd.OutputTo acOutputReport, , acFormatPDF, "location of the file for the export" + filename, , , , acExportQualityScreen

Dim mailatt

Dim MI As Outlook.MailItem

Set MI = outl.CreateItem(olMailItem)

MI.Body = ""

MI.Subject = "this is a text message which i include on all of my emails for this report"

MI.To = "enter your email addresses of your receipients" use ampersand & to add additional email addresses example :"email address" & "email address#2"

mailatt = "location and file name to be attached." example c:\documents\name of file.ext

MI.Attachments.Add (mailatt)

MI.send

Set MI = Nothing
Set outl = Nothing

after i got this working, i created a linked database to my original database, created and autoexec macro that would call this module. I set up a windows task for the same time every work day (monday through friday) to run this database and it would send this report without me needing to be present.

AOB thank you for the direction to the article.
 

AOB

Registered User.
Local time
Today, 15:35
Joined
Sep 26, 2012
Messages
560
Excellent, glad to be of help!
 

Users who are viewing this thread

Top Bottom