Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286

    Sending Report from Access as attachment in Email

    Hello, I have a report that is generated in access. When a user clicks a button, an email opens up and i want this report to be part of the attachment. I found this code, but it opens up a separate email with the attached report. How do i get it to appear on the first email?


    code i use to add attachment but opens up in separate email screen:

    DoCmd.SendObject acSendReport, "report", acFormatHTML

    Code i have to open up email with body information in it:

    Dim strEMail As String
    Dim oOutlook As Object
    Dim oMail As Object
    Dim strAddr As String
    Dim MyDB As DAO.Database
    Dim rstEMail As DAO.Recordset

    Set oOutlook = CreateObject("Outlook.Application")
    Set oMail = oOutlook.CreateItem(0)




    With oMail
    .HTMLBody = "<HTML><body>" & _
    "Hi, "
    .Display
    End With



    So the idea is to incorporate the attached report into the second half of the code i provided.


    Thanks!

  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,521
    You would need to output it first to create a file, then attach it. You can adapt the code to attach it from here:

    http://support.microsoft.com/?kbid=161088
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    thank you for the link,

    im sorry im nott adept at using vb coding. I am having trouble applying the code on that link to my code above. Can you help me modify it so that it fits the report im trying to attach? thanks!

  4. #4
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    i get that i need a path to send the report to but how do i output the report to a folder for example? this way i can input the path

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can use

    DoCmd.OutputTo..

    with the appropriate arguments, one of which is path.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    hello, thank you for the help. however, i dont know what i am supposed to type in after this part?

    DoCmd.OutputTo acOutputReport, "report",

    i would like the output to be in HTML/text format, how would i set the path to lets say Cesktop?



    thanks..ive tried searching but nothing fits my exact issue..

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Just so we're clear, as I've just realized I may have misunderstood, are you trying to attach the report to the email as an attachment (my original assumption), or embed the HTML of the report in the body of the email? I've never tried to do that, though I suppose it's possible.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    sorry if i was being unclear, i am trying to attach the report (which needs to be converted to HTML format) to my email. Thats why my original code was:

    DoCmd.SendObject acSendReport, "report_amr_exception_open_by_division", acFormatHTML

    however, it opens up a separate email window rather than attaching to the email i want it to attach to. thanks

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Here's an example with a dynamic file name previously set:

    DoCmd.OutputTo acOutputReport, "rptUnpaidInvoices", acFormatPDF, "C:\intacc\" & strFileName & ".pdf"

    then your code in the email would look like:

    objAttachment.Add "C:\intacc\" & strFileName & ".pdf"

    If you look in help on OutputTo, you'll find the change necessary to make it an html file.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    in your code what does the "strFileName" represent? is that a variable i need to dim?

  11. #11
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    i have:

    Dim objAttachment As Outlook.Attachment

    but im getting this error "user defined type not defined"

    im calling it in:

    objAttachment.Add "C:\folder stuff\" & strFileName & ".html"

    and this is code for the output:

    DoCmd.OutputTo acOutputReport, "report", acFormatHTML, "C:\folder stuff\" & strFileName & ".html"

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You're using late binding (which is not a bad thing), so try these lines:

    Dim objAttachment As Object
    Set objAttachment = oOutlook.Attachments
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    By the way, strFileName was a variable I set earlier to the name I wanted for the file. You don't need it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    hello, thanks again for all the help youve been offering, much appreciated. Now, i am getting an error for this line " Set objAttachment = oOutlook.Attachments". Error is: Object doesnt support this property or method. Here is my code:




    Dim strEMail As String
    Dim oOutlook As Object
    Dim oMail As Object
    Dim objAttachment As Object


    Set oOutlook = CreateObject("Outlook.Application")
    Set oMail = oOutlook.CreateItem(0)
    Set objAttachment = oOutlook.Attachments

    strEMail = strEMail & Me![tb_email_list_by_division] & ";"

    DoCmd.OutputTo acOutputReport, "report_amr_exception_open_by_division", acFormatHTML, "C:\stuff\" & ".html"


    With oMail

    .Subject = "PROBLEM SITE "
    .to = Left$(strEMail, Len(strEMail) - 1)
    .cc =

    objAttachment.Add "C:\stuff\" & ".html"


    .HTMLBody = "<HTML><body>" & _

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sorry, I think I had a cut/paste accident.

    Try:

    Set objAttachment = oMail.Attachments

    It needs to be the mail variable, not the Outlook variable.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. sending gmail email through access
    By TheShabz in forum Programming
    Replies: 20
    Last Post: 02-19-2012, 12:24 PM
  2. Replies: 6
    Last Post: 12-12-2011, 09:57 PM
  3. Replies: 2
    Last Post: 08-17-2010, 10:54 AM
  4. Replies: 0
    Last Post: 07-06-2010, 08:12 AM
  5. SENDING EMAIL MESSAGES DIRECTLY FROM ACCESS
    By Frenchos in forum Access
    Replies: 0
    Last Post: 07-20-2007, 12:51 AM

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