Results 1 to 3 of 3
  1. #1
    gibbons916 is offline Novice
    Windows 10 Office 365
    Join Date
    Feb 2021
    Posts
    1

    Converting Report to an email body

    Hello,
    So I found a code that helped me send a report in outlook, in the body. However, some things are not transferring.
    This is what a report looks like in the MS Access:
    Click image for larger version. 

Name:	View report.PNG 
Views:	11 
Size:	22.6 KB 
ID:	44171

    This is what the report looks like when transferring this report to outlook:
    Click image for larger version. 

Name:	Email view.PNG 
Views:	11 
Size:	55.8 KB 
ID:	44172

    I'm okay with how it turned out, except I have a conditional formatting for the red/green text that says 'Tool is up/Tool is down'. I would like to get that conditional formatting to work on the email. Can anyone help me alter the following code to fix that?

    Option Compare Database
    Option Explicit


    Private Sub Command28_Click()

    Dim sFile As String, lFile As Long, sHtml As String
    Dim olApp As Outlook.Application
    Dim olMail As Outlook.MailItem

    'Output the report to HTML in the temp directory
    sFile = Environ$("TEMP") & "\DailyReport" & Format(Date, "yyyymmdd") & ".html"
    DoCmd.OutputTo acOutputReport, "rptDailyReport", acFormatHTML, sFile

    'Read in the HTML File
    lFile = FreeFile

    Open sFile For Input As lFile
    sHtml = Input$(LOF(lFile) - 1, lFile)
    Close lFile


    'Put the file contents in the email body
    Set olApp = New Outlook.Application
    Set olMail = olApp.CreateItem(olMailItem)
    olMail.To = "ThisPerson@email.com"


    olMail.Subject = "Daily Report " & Date
    olMail.HTMLBody = sHtml
    olMail.Display

    End Sub


    I am running on Windows 10/Office 365.

    Thanks in advance!

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    I'd inspect sHtml to see what it contains.?
    You could use Replace() to add the html color codes for the relevant text?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    You will never be able to exactly replicate your report in Outlook.
    HTML features will not display if users' email app is set to plain text.
    Even if you included images to solve formatting issues, many email apps block inline images.

    Why not just export the report to PDF and attach it to the email?
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Email Report in Body
    By stu_C in forum Reports
    Replies: 5
    Last Post: 02-01-2017, 02:20 PM
  2. Replies: 3
    Last Post: 05-18-2015, 11:24 AM
  3. Email report as body of email (RTF)
    By TheDeceived in forum Programming
    Replies: 4
    Last Post: 07-23-2012, 06:39 AM
  4. Email report as body of email
    By chrish20202 in forum Programming
    Replies: 6
    Last Post: 01-15-2012, 07:23 PM
  5. Email from report to Email body
    By Ehmke66 in forum Programming
    Replies: 4
    Last Post: 01-03-2011, 01:06 PM

Tags for this Thread

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