Email report without using DoCmd and avoid Outlook Security dialogue box (1 Viewer)

ITguy1981

Registered User.
Local time
Yesterday, 19:54
Joined
Aug 24, 2011
Messages
137
I'd like to be able to automatically send a report from Access through Outlook. Currently, I started with:

DoCmd.SendObject acSendReport, "rpt30Warning", acFormatPDF, "myaddress@domain.com", , , "Expiratations in 30 days", "Please see attached PDF.", False

I later found I can't use this because of the security popup from Outlook. I don't know how else to achieve sending this report. Please help!
 

Insane_ai

Not Really an A.I.
Local time
Yesterday, 19:54
Joined
Mar 20, 2009
Messages
264
https://www.access-programmers.co.uk/forums/showthread.php?t=262042

Try the code included in the post above unless you need to interact with the email.

Then try this:
Code:
Public Sub CreateEmail(lFormat As Long, toEmail As String, Subject As String, body As String, Optional bSend As Boolean = False, Optional strAttachment As String, Optional strCC As String, Optional strBCC As String)
    Dim oApp As Object
    Dim mail As Object 'Outlook.MailItem
    Set oApp = CreateObject("Outlook.Application")
    Set mail = oApp.CreateItem(0)
    With mail
        If strAttachment <> "" Then .Attachments.Add strAttachment
        If strCC <> "" Then .CC = strCC
        If strBCC <> "" Then .Bcc = strBCC
        .BodyFormat = lFormat 'rich text
        .Subject = Subject
        If lFormat = 2 Then
            .HTMLBody = body
        Else
            .body = body
        End If
        .to = toEmail
        If bSend Then
            .Send
        Else
            .Display
        End If
    End With
    Set mail = Nothing
    Set oApp = Nothing
End Sub
 

Users who are viewing this thread

Top Bottom