Results 1 to 7 of 7
  1. #1
    chrish20202 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    4

    Email report as body of email

    I have searched and googled and searched for several months without finding an answer to my problem.



    I want the user to click a button (on the form) that generates an html report and sends an email, through Outlook 2010, with that report being the body of the email not as an attachment.

    I'm looking to accomplish this through VBA and I have tried everything that I can think of and still am unable to get it to work.

    Any help appreciated. I'm pulling out my hair out over this.

    Thanks a lot,
    Chris

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    Why doesn't work - error message, wrong results, nothing happens? Post code and/or attach project for analysis.
    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
    chrish20202 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    4
    Quote Originally Posted by June7 View Post
    Why doesn't work - error message, wrong results, nothing happens? Post code and/or attach project for analysis.
    To clarify, I haven't got any Access 2010 code to show. I was using the below code in Excel 2003 but, in researching, found that this won't work in Access 2010. It works perfect in Excel 2003. Also, to be fair, the code is not my personal work but primarly an example I found googling a few years ago.

    I guess my question would be more accurate as: How do I do the below in Access 2010? I can figure out how to create an html file but this part seems to escape me.

    Thanks

    Excel VBA code:

    Code:
    Sub email()
    
        Dim FSO As Object
        Dim HTMLcode As String
        Dim HTMLfile As Object
        Dim myOlApp As Object
        Dim myOlMail As Object
    
        ' Read all data from the TempFile which now in HTML
           Set FSO = CreateObject("Scripting.FileSystemObject")
           Set HTMLfile = FSO.GetFile(sFNmht).OpenAsTextStream(1, -2)
             HTMLcode = HTMLfile.ReadAll
             HTMLfile.Close
             HTMLcode = Replace(HTMLcode, "align=center x:publishsource=", _
                              "align=left x:publishsource=")
             
        ' Start Outlook
           Set myOlApp = CreateObject("Outlook.Application")
        ' Create the mail item and send it.   
           Set myOlMail = myOlApp.CreateItem(0)
            With myOlMail
               .To = "DL-team; DL-SRT"
               .Subject = "Paramedic Telemetry DSEL for " & Format(Sheets("TSEL").Range("B2"), "dd-mmm-yyyy")
               .HTMLBody = HTMLcode
               .Send
            End With
         
        ' Cleanup and Release Objects from memory
           Set myOlMail = Nothing
           Set myOlApp = Nothing
           Set HTMLfile = Nothing
           Set FSO = Nothing
    
    End Sub

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    Everything I read says cannot make an Access report the body of an email. But you say you are generating an HTML report. HTML report would be a bunch of text with HTML tags. Should be able to make this the body of email. Access VBA can send email with HTML tagged text. I guess trick is getting the HTMLCode variable populated. I really don't see why the VBA won't work in Access as well as Excel. Have you tested? Do you want to provide files for analysis?
    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
    chrish20202 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    4
    Quote Originally Posted by June7 View Post
    Everything I read says cannot make an Access report the body of an email. But you say you are generating an HTML report. HTML report would be a bunch of text with HTML tags. Should be able to make this the body of email. Access VBA can send email with HTML tagged text. I guess trick is getting the HTMLCode variable populated. I really don't see why the VBA won't work in Access as well as Excel. Have you tested? Do you want to provide files for analysis?

    Thanks a lot for the reply.

    I have not tried to create an html report but surely access is able to generate a web page??

    I'm still searching and trying but not giving up yet! Thanks

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    Access can export to HTML, XML, CSV, Excel, Word, ODBC, dBase, Sharepoint List. There is a wizard for that. At least some of which can be replicated with VBA.
    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.

  7. #7
    chrish20202 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    4
    Quote Originally Posted by June7 View Post
    Access can export to HTML, XML, CSV, Excel, Word, ODBC, dBase, Sharepoint List. There is a wizard for that. At least some of which can be replicated with VBA.
    I think I might be making a little headway. I'm gonna create a sample database and I'll ul it here when i'm done.

    thanks for help!

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

Similar Threads

  1. Replies: 1
    Last Post: 05-23-2011, 08:07 AM
  2. Email from report to Email body
    By Ehmke66 in forum Programming
    Replies: 4
    Last Post: 01-03-2011, 01:06 PM
  3. Export Contents of a Report into Email Body
    By Nosaj08 in forum Reports
    Replies: 4
    Last Post: 05-27-2009, 09:05 AM
  4. Field Name into Subject/Body of an email?
    By Stanggirlie in forum Programming
    Replies: 0
    Last Post: 01-05-2009, 11:51 AM
  5. Email field name into subject/body?
    By Stanggirlie in forum Access
    Replies: 0
    Last Post: 01-02-2009, 11:07 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