Results 1 to 11 of 11
  1. #1
    MEMFBI is offline Advanced Beginner
    Windows 10 Access 2003
    Join Date
    Apr 2020
    Posts
    39

    How ro insert a table into the body of an email

    Hello
    I am trying to insert a table into the body of an email being generated from access.
    The email process is working. I am having an issue inserting the table into the body.
    I want 2 fields Job_Name and Created from table Email_Contracts
    Apologies up front, I am unfamiliar with the proper coding for HTML, so obviously I have something wrong.
    I am receiving error msg: Run Time error 424 object required on the line:

    .HTMLBody = "<!DOCTYPE html><html><body><table><tr><td>Job_Name</td><td>Created</td></tr>" & strHTML & "</table></body></html>"

    Below is the code

    Click image for larger version. 

Name:	Email_error.png 
Views:	19 
Size:	56.4 KB 
ID:	45248



    Thank you!

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,969
    Better to post code within code tags (# on posting toolbar) rather than pictures. You didn't say what the error was or even if there is one. Is it breaking on the highlighted line?
    If so all I can think of is that either myMail isn't declared, or if it is, it cannot have .HTMLBody as a member IF this is an Access problem. If it's an html problem, then IIRC attributes must be encased in quotes as in
    <td style="text-align:right">

    In that case, you'd have to try single quotes and if html doesn't like that, you'd need to escape double quotes or use chr(34) as a work around.
    Maybe this will help
    https://www.w3schools.com/tags/tag_table.asp
    Last edited by Micron; 05-18-2021 at 11:23 AM. Reason: added info
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

  3. #3
    MEMFBI is offline Advanced Beginner
    Windows 10 Access 2003
    Join Date
    Apr 2020
    Posts
    39
    I did state, above the code what and where the error was occurring:

    I am receiving error msg: Run Time error 424 object required on the line:


    .HTMLBody = "<!DOCTYPE html><html><body><table><tr><td>Job_Name</td><td>Created</td></tr>" & strHTML & "</table></body></html>"

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,969
    My apologies, I missed that. Then show how/where myMail is declared? If you comment out that line and get the same error on the next line, that indicates to me that Access doesn't know what myMail is. Are you using Option Explicit at the top of all of your modules?
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

  5. #5
    MEMFBI is offline Advanced Beginner
    Windows 10 Access 2003
    Join Date
    Apr 2020
    Posts
    39
    I have declared myMAil as a Variant. I have added Option Explicit. I have commented out the line causing the error, and the process runs.
    Is there a better way to include data in the body of the email?
    Perhaps I am not using the best process?

    Thank you

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,969
    I would have used an object variable for an object but since it's happy with myMail.BodyFormat it must be something within that string. Have to leave this for a few hours. Will come back to see if it's solved.
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

  7. #7
    MEMFBI is offline Advanced Beginner
    Windows 10 Access 2003
    Join Date
    Apr 2020
    Posts
    39
    I have gotten the email to send. Have issues within the HTML. Presuming I am missing quotes some where:

    Code:
     With myMail
            Do Until rst.EOF
               strHTmL = strHTmL & "<tr><td style='padding: 10px; border-style: solid; border-color: #ccc; border-width: 1px 1px 0 0;'>" & rst![Job_Name] & "</td>"
               strHTmL = strHTmL & "<tr><td style='padding: 10px; border-style: solid; border-color: #ccc; border-width: 1px 1px 0 0;'>" & rst![Created] & "</td></tr>"
               rst.MoveNext
            Loop
           
            HTMLBody = "<!DOCTYPE html><html><body><table><tr><td>Job_Name</td><td>Created</td></tr>" & strHTmL & "</table></body></html>"
        End With
    The body of the email mirrors the statements above, with the data where the field names would be.

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,969
    Presuming I am missing quotes some where:
    My html is quite rusty, plus a lot of it was deprecated by CSS so I would have to agree with you. I would output the html as a string, paste it into a notepad document as test.htm and see how it looks in the hopes that the issue is revealed. Since I don't have your strHTML output, I can only test the outer portions. I get

    "
    Job_Name Created
    "

    and the leading and trailing quotes seem a bit odd.
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

  9. #9
    MEMFBI is offline Advanced Beginner
    Windows 10 Access 2003
    Join Date
    Apr 2020
    Posts
    39
    Switch to "text" all is is fine. Don't know why I thought that it had to be HTML.

    Below is the result of the output trying to use HTML

    <!DOCTYPEhtml><html><body><table><tr><td>Job_Nam e</td><td>Created</td></tr><tr><tdstyle='padding: 10px; border-style: solid; border-color: #ccc; border-width:1px 1px 0 0;'>48 BOSTON POST RD./WAREHOUSE</td><tr><tdstyle='padding: 10px; border-style: solid; border-color: #ccc; border-width:1px 1px 0 0;'>5/4/2021 11:41:29 AM</td></tr><tr><tdstyle='padding: 10px; border-style: solid; border-color: #ccc; border-width:1px 1px 0 0;'>testing</td><tr><td style='padding: 10px;border-style: solid; border-color: #ccc; border-width: 1px 1px 00;'>5/4/2021 3:28:59 PM</td></tr><tr><tdstyle='padding: 10px; border-style: solid; border-color: #ccc; border-width:1px 1px 0 0;'>testing</td><tr><td style='padding: 10px;border-style: solid; border-color: #ccc; border-width: 1px 1px 00;'>5/4/2021 3:46:15 PM</td></tr><tr><tdstyle='padding: 10px; border-style: solid; border-color: #ccc; border-width:1px 1px 0 0;'>10 EXCHANGE PL./LOBBY</td><tr><tdstyle='padding: 10px; border-style: solid; border-color: #ccc; border-width:1px 1px 0 0;'>5/18/2021 9:58:08 AM</td></tr><tr><tdstyle='padding: 10px; border-style: solid; border-color: #ccc; border-width:1px 1px 0 0;'>AEROFARMS/PHASE 2B EXPANSION</td><tr><tdstyle='padding: 10px; border-style: solid; border-color: #ccc; border-width:1px 1px 0 0;'>5/18/2021 10:00:47 AM</td></tr><tr><tdstyle='padding: 10px; border-style: solid; border-color: #ccc; border-width:1px 1px 0 0;'>CHOP/COLKET BLDG.-LEVEL 2 ENAB</td><tr><tdstyle='padding: 10px; border-style: solid; border-color: #ccc; border-width:1px 1px 0 0;'>5/18/2021 10:02:46 AM</td></tr><tr><tdstyle='padding: 10px; border-style: solid; border-color: #ccc; border-width:1px 1px 0 0;'>STATEN IS. UNIV. HOSP./NORTH C</td><tr><tdstyle='padding: 10px; border-style: solid; border-color: #ccc; border-width:1px 1px 0 0;'>5/18/2021 10:03:28 AM</td></tr><tr><tdstyle='padding: 10px; border-style: solid; border-color: #ccc; border-width:1px 1px 0 0;'>10 EXCHANGE PL./LOBBY</td><tr><tdstyle='padding: 10px; border-style: solid; border-color: #ccc; border-width:1px 1px 0 0;'>3/16/2021 12:33:39PM</td></tr></table></body></html>

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,969
    Doesn't look properly formed to me but as I said, my html is rusty. At first glance there's a missing </tr> for the first row plus multiple attributes are formed as

    <td style="background-color:#FF0000" "border-style:solid" "border-color:#ccc">

    whereas you have semicolons separating them. If you're happy with your email being text type then you seem to have a solution and can mark this as solved. However, your post was about constructing a table for email and AFAIK, you can't have tables in text formatted email. You would be lucky if everything lined up.
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

  11. #11
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,969
    Disregard my comment about the missing </tr> as it was hard to make sense of the result of your posted code (it resulted in a long run-on jumble of words and was difficult to decipher). I think what you want your html to look like is closer to below, although you wouldn't have to format it to the same level.
    Code:
    <html>
        <body>
            <table>
                <tr><td>Job_Name</td><td>Created</td></tr>
                <tr>
                    <td style="padding:10px" "border-style:solid" "border-color:#ccc" "border-width:1px">48 BOSTON POST RD./WAREHOUSE</td>
                    <td style="padding:10px" "border-style:solid" "border-color:#ccc" "border-width:1px">5/4/2021 11:41:29 AM</td>
                </tr>
                <tr>
                    <td style="padding:10px" "border-style:solid" "border-color:#ccc" "border-width:1px">testing</td>
                    <td style="padding:10px" "border-style:solid" "border-color:#ccc" "border-width:1px">5/4/2021 3:28:59 PM</td>
                </tr>
                <tr>
                    <td style="padding:10px" "border-style:solid" "border-color:#ccc" "border-width:1px">testing</td>
                    <td style="padding:10px" "border-style:solid" "border-color:#ccc" "border-width:1px">5/4/2021 3:46:15 PM</td>
                </tr>
                <tr>
                    <td style="padding:10px" "border-style:solid" "border-color:#ccc" "border-width:1px">10 EXCHANGE PL./LOBBY</td>
                    <td style="padding:10px" "border-style:solid" "border-color:#ccc" "border-width:1px">5/18/2021 9:58:08 AM</td>
                </tr>
                <tr>
                    <td style="padding:10px" "border-style:solid" "border-color:#ccc" "border-width:1px">AEROFARMS/PHASE 2B EXPANSION</td>
                    <td style="padding:10px" "border-style:solid" "border-color:#ccc" "border-width:1px">5/18/2021 10:00:47 AM</td>
                </tr>
                <tr>
                    <td style="padding:10px" "border-style:solid" "border-color:#ccc" "border-width:1px">CHOP/COLKET BLDG.-LEVEL 2 ENAB</td>
                    <td style="padding:10px" "border-style:solid" "border-color:#ccc" "border-width:1px">5/18/2021 10:02:46 AM</td>
                </tr>
                <tr>
                    <td style="padding:10px" "border-style:solid" "border-color:#ccc" "border-width:1px">STATEN IS. UNIV. HOSP./NORTH C</td>
                    <td style="padding:10px" "border-style:solid" "border-color:#ccc" "border-width:1px">5/18/2021 10:03:28 AM</td>
                </tr>
                <tr>
                    <td style="padding:10px" "border-style:solid" "border-color:#ccc" "border-width:1px">10 EXCHANGE PL./LOBBY</td>
                    <td style="padding:10px" "border-style:solid" "border-color:#ccc" "border-width:1px">3/16/2021 12:33:39PM</td>
                </tr>
            </table>
        </body>
    </html>
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

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

Similar Threads

  1. Replies: 3
    Last Post: 09-25-2018, 11:37 AM
  2. email a form in the body of an email?
    By rudyebiii in forum Forms
    Replies: 2
    Last Post: 10-08-2016, 07:58 AM
  3. Replies: 3
    Last Post: 05-18-2015, 11:24 AM
  4. Email report as body of email
    By chrish20202 in forum Programming
    Replies: 6
    Last Post: 01-15-2012, 07:23 PM
  5. Import Data from a Table in the Body of an Email
    By a1195423 in forum Import/Export Data
    Replies: 0
    Last Post: 03-24-2011, 01:55 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 - Senior Forums