Results 1 to 2 of 2
  1. #1
    swenger is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2016
    Posts
    151

    Code to email Report from Form

    I had this button on a form which would generate a PDF of a report that would be saved in a specific location on my computer and then email a copy to a group of people. This works. I would like to now email a different form in PDF without saving it to my computer location and I am getting an error in the path. I tried using a Windows variable like %tmp% so it can be saved temporarily but access won't recognize this variable. Probably my code needs to be modified so i am attaching it below

    The variables used in the code are already declared Public



    Code:
    Private Sub emailTest_Click()
    
    On Error GoTo emailTest_Click_Err
    
    
        flnm = "RMA " & RMAN & " TKT " & TicketN & ".pdf"
        Sbj = "RMA# " & RMAN & " / TKT# " & TicketN
    
    
        DoCmd.OutputTo acOutputReport, "RRMAPDF", acFormatPDF, flnm, , , , 0
           
    Dim appOutLook As Outlook.Application
    Dim MailOutLook As Outlook.MailItem
    Dim MailAttachment As Outlook.Attachments
    
    
        Set appOutLook = CreateObject("Outlook.Application")
        Set MailOutLook = appOutLook.CreateItem(olMailItem)
        MailOutLook.Display
        With MailOutLook
            .subject = Sbj
            .To = Me.Email
            .CC = "support@domain.com"
            .Attachments.Add flnm
            .Display 'This will display the message for you to check and send yourself
    '       .Send ' This will send the message straight away
        End With
        
    emailTest_Click_Exit:
        Exit Sub
    
    
    emailTest_Click_Err:
        MsgBox Error$
        Resume emailTest_Click_Exit
        
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Being lazy, I'd just save it to the path you know works and then delete the file after the email is sent.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 03-26-2014, 10:04 AM
  2. Replies: 1
    Last Post: 02-25-2013, 03:16 PM
  3. Replies: 1
    Last Post: 06-26-2012, 08:19 PM
  4. Replies: 1
    Last Post: 02-14-2012, 07:08 PM
  5. VBA Code to report syntax errors via email
    By jazzkenney in forum Programming
    Replies: 6
    Last Post: 11-30-2011, 08:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums