Emailing Report (1 Viewer)

vito1010

Registered User.
Local time
Today, 18:21
Joined
Aug 14, 2014
Messages
33
When I use VBA to email a report
- DoCmd.SendObject acReport, "Letter 2022", "PDFFormat(*.pdf)", [RealEmail], , , "Tax Return Submission " & Format(Date, " mm/dd/yy"), "Thank you", 0

I get a warning (from Outlook) that a program is trying to send email on my behalf. Is there a way to prevent that warning?

Thank you.
 

Ranman256

Well-known member
Local time
Today, 18:21
Joined
Apr 9, 2015
Messages
4,339
what version of Outlook? Older Outlooks have this message to prevent evil code running it.
you may have to send it in access via outlook code,
make pdf file, then send via email:

'NOTE : YOU MUST HAVE THE OUTLOOK REFERENCE CHECKED IN VBE; Alt-F11, menu,tools, references, Microsoft Outlook XX Object library
Code:
sub SendFileThruEmail()
dim vFile
vFile = "c:\temp\Myfile.pdf
DoCmd.OutputTo acOutputReport, "rMyReport", acFormatPDF, vFile
send1email "w.e.coyote@acme.com","subject","body",vFile
end sub

Public Function Send1Email(ByVal pvTo, ByVal pvSubj, ByVal pvBody, Optional ByVal pvFile) As Boolean
Dim oApp As Outlook.Application
Dim oMail As Outlook.MailItem
On Error GoTo ErrMail

'NOTE : YOU MUST HAVE THE OUTLOOK REFERENCE CHECKED IN VBE; Alt-F11, menu,tools, references, Microsoft Outlook XX Object library
Set oApp = GetApplication("Outlook.Application")  'it may be open already so use this
'Set oApp = CreateObject("Outlook.Application")  'not this
Set oMail = oApp.CreateItem(olMailItem)
With oMail
.To = pvTo
.Subject = pvSubj
If Not IsMissing(pvFile) Then .Attachments.Add pvFile, olByValue, 1

.HTMLBody = pvBody
'If Not IsNull(pvBody) Then .Body = pvBody

'.Display True 'show user but dont send yet
.Send 'send now
End With
Send1Email = True
Endit:
Set oMail = Nothing
Set oApp = Nothing
Exit Function
ErrMail:
MsgBox Err.Description, vbCritical, Err
Resume Endit
End Function

Function GetApplication(className As String) As Object
' function to encapsulate the instantiation of an application object
Dim theApp As Object
On Error Resume Next
Set theApp = GetObject(, className)
If Err.Number <> 0 Then
MsgBox "Unable to Get" & className & ", attempting to CreateObject"
Set theApp = CreateObject(className)
End If
If theApp Is Nothing Then
Err.Raise Err.Number, Err.Source, "Unable to Get or Create the " & className & "!"
Set GetApplication = Nothing
End If
'MsgBox "Successfully got a handle on Outlook Application, returning to caller"
Set GetApplication = theApp
End Function
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 15:21
Joined
Aug 30, 2003
Messages
36,118
In Outlook check File/Options/Trust Center/Trust Center Settings/Programmatic Access. If the anti virus setting is Valid you should be able to send without warnings.
 

vito1010

Registered User.
Local time
Today, 18:21
Joined
Aug 14, 2014
Messages
33
It's Office 2013. There is no Programmatic Access tab in this version.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 15:21
Joined
Aug 30, 2003
Messages
36,118
It's Office 2013. There is no Programmatic Access tab in this version.

There is on mine. It's in Outlook, not Access.

1652363352429.png

1652363364915.png
 

Users who are viewing this thread

Top Bottom