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

    Converting Report to an email body

    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 = ""
    olMail.Subject = "Daily Report " & Date
    olMail.HTMLBody = sHtml


    End Sub

    I am running on Windows 10/Office 365.

    Thanks in advance!

  2. #2
    Welshgasman is offline Expert
    Windows 10 Access 2007
    Join Date
    Jan 2017
    Swansea,South Wales,UK
    I'd inspect sHtml to see what it contains.?
    You could use Replace() to add the html color codes for the relevant text?
    Please, please use # when posting code snippets.
    Cross Posting Etiquette:
    Debugging Access:

  3. #3
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Somerset, UK
    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 (Mendip Data Systems): Website, email
    Try again. Fail again. Fail better.
    sking for help isn't giving up. Its refusing to give up.

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 - Senior Forums