Results 1 to 9 of 9
  1. #1
    Fionfion is offline Novice
    Windows 8 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    25

    Conditional formatting not working when I use the acOutputReport command

    Hi, I'm currently working on a database that allows users to email report as email content not attachment, it works except the conditional formatting is not showing, may I know whether it is possible? I got the code from the internet:



    Code:
    Sub RTFBodyX()
    Const ForReading = 1, ForWriting = 2, ForAppending = 3
    Dim fs, f
    Dim RTFBody, strTo
    Dim MyApp As New Outlook.Application
    Dim MyItem As Outlook.MailItem
    
    DoCmd.OutputTo acOutputReport, "Statement", acFormatHTML, "Report1.htm"
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.OpenTextFile("Report1.htm", ForReading) 
    RTFBody = f.ReadAll
    f.Close
    Set MyItem = MyApp.CreateItem(olMailItem)
    With MyItem
    .To = "a@b.c"
    .Subject = "Subject"
    .HTMLBody = RTFBody
    End With
    MyItem.Display
    End Sub
    
    Private Sub Command33_Click()
    Call RTFBodyX
    End Sub
    Also, I note that anything after
    RTFBody
    would not show in the email, please help as I wanted to put the report in the middle of the email content.

    Thank you very much in advance!!

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    You aren't declaring any data types for most of your variables.

    Dim fs, f will declare both as Variants types, the same with RTFBody, strTo .

    The code as is also using early binding, which might fail on another machine with a different office version.
    What do you mean by anything after RTFBody won't show - as far as I can see there isn't anything added after the mail body ?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Fionfion is offline Novice
    Windows 8 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    25
    Quote Originally Posted by Minty View Post
    You aren't declaring any data types for most of your variables.

    Dim fs, f will declare both as Variants types, the same with RTFBody, strTo .

    The code as is also using early binding, which might fail on another machine with a different office version.
    What do you mean by anything after RTFBody won't show - as far as I can see there isn't anything added after the mail body ?
    Thanks for your help, I actually don't know how to write codes and just got the codes from the internet, is there a better code for this? For me I have not run it on a different computer so I don't know whether it would work yet. How about the conditional formatting, is it possible to show in the email?

    So I added the following codes:
    Code:
    Dim fs, f As Variant
    Dim RTFBody, strTo As Variant
    I mean when I tried to add any text after
    RTFBody
    it would not show, I just do like this:
    Code:
    .HTMLBody = "Some texts" & RTFBody & "Any texts" 
    "Some texts" would show but "Any texts" would not.

  4. #4
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Okay - the RTFBody will be in HTML mark up - which is what the email editor is expecting to see.
    So you would have the following as the same plain text and then the html equivalent;

    Code:
     Dim txtBody as string
     Dim txtHTMLBody as string
     txtBody = "Good " & Greeting & sContact & "," & vbCrLf & _
                  vbCrLf & _
                  "Please find attached your " & Variable_Subject & vbCrLf & _
                  vbCrLf & _
                  "Please arrange for a PO to be sent over if you wish to proceed."
    
    
    
    
         txtHTMLBody = "<style> " & _
                        "p {font-size:12pt; font-family:Calibri}" & _
                        "</style>" & _
                        "<p>" & "Good " & Greeting & sContact & "," & "</p>" & _
                        "<p>" & "" & "</p>" & _
                        "<p>" & "Please find attached your " & Variable_Subject & " <br/>" & _
                        "<p>" & "" & "</p>" & _
                        "<p>" & "Please arrange for a PO to be sent over if you wish to proceed. <br/>" & _
                        "<p>" & "" & "</p>" & _
                        "<p>" & "Kind regards,<br/>"
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    Fionfion is offline Novice
    Windows 8 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    25
    Thank you Minty, but due to my very limited VBA knowledge.. I don't understand.. I tried to add the following:
    Code:
    Dim txtBody As String
    Dim txtHTMLBody As String
     
    txtBody = RTFBody & "Any text"
    txtHTMLBody = RTFBody & "Any text"
                        
    .Body = txtBody
    .HTMLBody = txtHTMLBody
    It shows the same thing, no conditional formatting, no text shown after
    RTFBody


  6. #6
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    I'm not sure the conditional formatting would show up, but lets get you on the right track first.

    I was trying to demonstrate (very badly) that to get additional text to display you will have format it in HTML tags.
    And you can only have either .Body or .HTMLBody not both. So try

    txtHTMLBody = RTFBody & "<p>Any text</p>"
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  7. #7
    Fionfion is offline Novice
    Windows 8 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    25
    Quote Originally Posted by Minty View Post
    I'm not sure the conditional formatting would show up, but lets get you on the right track first.

    I was trying to demonstrate (very badly) that to get additional text to display you will have format it in HTML tags.
    And you can only have either .Body or .HTMLBody not both. So try

    txtHTMLBody = RTFBody & "<p>Any text</p>"
    Not working
    I even tried
    txtHTMLBody = "<P>" & RTFBody & "</P>" & "<p>Any text</p>"

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    I don't think Conditional Formatting will translate to HTML.

    Your code doesn't show file path. How does it know where to save to and retrieve from?

    The htm file is created with closing BODY and HTML tags so I tried this:

    RTFBody = Replace(f.ReadAll, vbCrLf & vbCrLf & "</BODY>" & vbCrLf & "</HTML>", "") & "<TABLE><TR><TD>Any text</TD></TR></TABLE></BODY></HTML>"
    f.Close
    Debug.Print RTFBody

    The Debug output shows the modified HTML string but the email still will not include the appended text.

    I can get email to receive either the file content or the extra text but not both together.

    Very frustrating.

    FOUND IT! The htm file is created with a Nul code at the end of the file. I manually deleted it and then the combined text output to the email. I used Notepad++ to view the htm file.

    OKAY, this strips the Nul character and shows the combined string in email:

    RTFBody = Replace(f.readall, Chr(0), "") & "Any text"
    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.

  9. #9
    Fionfion is offline Novice
    Windows 8 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    25
    Quote Originally Posted by June7 View Post
    I don't think Conditional Formatting will translate to HTML.

    Your code doesn't show file path. How does it know where to save to and retrieve from?

    The htm file is created with closing BODY and HTML tags so I tried this:

    RTFBody = Replace(f.ReadAll, vbCrLf & vbCrLf & "</BODY>" & vbCrLf & "</HTML>", "") & "<TABLE><TR><TD>Any text</TD></TR></TABLE></BODY></HTML>"
    f.Close
    Debug.Print RTFBody

    The Debug output shows the modified HTML string but the email still will not include the appended text.

    I can get email to receive either the file content or the extra text but not both together.

    Very frustrating.

    FOUND IT! The htm file is created with a Nul code at the end of the file. I manually deleted it and then the combined text output to the email. I used Notepad++ to view the htm file.

    OKAY, this strips the Nul character and shows the combined string in email:

    RTFBody = Replace(f.readall, Chr(0), "") & "Any text"
    Thanks it worked

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

Similar Threads

  1. Conditional formatting *almost* working
    By skyatis in forum Programming
    Replies: 2
    Last Post: 01-27-2017, 01:55 PM
  2. Replies: 11
    Last Post: 11-25-2016, 07:26 PM
  3. Replies: 2
    Last Post: 10-15-2015, 11:46 AM
  4. Conditional Formatting Not Working Properly
    By davidmcleod in forum Access
    Replies: 14
    Last Post: 06-25-2015, 11:04 AM
  5. Conditional Formatting not working properly
    By GraeagleBill in forum Reports
    Replies: 3
    Last Post: 03-08-2014, 07:21 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