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

    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:	8 
Size:	56.4 KB 
ID:	45248

    Thank you!

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,790
    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; Today 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
    32
    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 online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,790
    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
    32
    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 online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,790
    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
    32
    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 online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,790
    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.

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