Results 1 to 6 of 6
  1. #1
    teebumble is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    21

    Attach Report to Email

    Hi,

    I have a report that I would like to attach to an email automatically. Is that possible?



    Code:
     
    Private Sub Report_Page()
        Dim DailyReport As String
        
        DoCmd.OutputTo acOutputReport, DailyReport, _
        acFormatRTF, "DailyReport.rtf", True
        DoCmd.Save acReport, "DailyReport"    'this line doesn't work
        
        Dim iMsg, cdoConfig As Object
        Dim sch, As String
             
        sch = "http://schemas.microsoft.com/cdo/configuration/"
        Set cdoConfig = CreateObject("CDO.Configuration")
        
        With cdoConfig.Fields
            .Item(sch & "sendusing") = 2
            .Item(sch & "smtpserver") = "Exchange._________.com" 'company name removed
            .Item(sch & "smtpserverport") = 25 
            .update
        End With
        
        Set iMsg = CreateObject("CDO.Message")
        With iMsg
            Set .Configuration = cdoConfig
            .To = "________.com" 'email removed
            .CC = ""
            .BCC = ""
            .From = "__________.com" 'email removed
            .Subject = "Weekly Training Updates"
            .TextBody = "Please see the attached document for training updates"
            .Addattachment "C:/" & savename    'this line doesn't work
            .Send
        End With
        
        Kill "C:/" & savename 'this line doesn't work
    
        Set iMsg = Nothing
        Set cdoConfig = Nothing
        
        DoCmd.Close acReport, "Daily Report"
    End Sub
    if i remove all the lines that i have commented "this line doesn't work" then the email is sent. So I know the email code works, but I can't attach my report. Any suggestions?

    thanks,

    teebumble

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Maybe this will help, reverse the / to \, like C:\
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    teebumble is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    21
    I changed the direction of the \. Thanks!

    But my .addattachment still doesn't work. I also tried .attachment.add ("______"), .addattachment = "_______", .attachment = " ".

    Any suggestions on adding attachment?

    Thanks!

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Checked my code again, syntax that works for me is:

    .Attachments.add
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    teebumble is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    21
    thanks June7. It was actually my fault. I typed the wrong path, so it was not in the correct location.

    THANKS AGAIN!

  6. #6
    hawkdriver's Avatar
    hawkdriver is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2012
    Posts
    23
    Wanted to delete my comments, but had to replace it with this.
    Last edited by hawkdriver; 11-30-2012 at 01:24 PM.

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

Similar Threads

  1. Replies: 2
    Last Post: 12-28-2011, 09:32 PM
  2. Replies: 4
    Last Post: 04-13-2011, 10:11 AM
  3. Email from report to Email body
    By Ehmke66 in forum Programming
    Replies: 4
    Last Post: 01-03-2011, 01:06 PM
  4. Can't attach to email
    By newtoAccess in forum Access
    Replies: 10
    Last Post: 12-03-2010, 02:10 PM
  5. Attach Email to Form
    By Huddle in forum Access
    Replies: 2
    Last Post: 07-22-2010, 12:39 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