Results 1 to 9 of 9
  1. #1
    onlylonely is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    May 2017
    Posts
    110

    Send email via access with table included

    Hi Guys,

    I would like to use form to send an email with table on the email body.
    May i know how to include table into the email body?

    For example:


    Hi All,

    Please review 123 and feedback to supplier for repeating reject.

    Part Rej Qty Supplier
    123 12 Apple


    Code:
    Public Function Email3()Dim oApp As Outlook.Application
    Dim oMail As MailItem
    Set oApp = CreateObject("Outlook.application")
    
    
    Set oMail = oApp.CreateItem(olMailItem)
    oMail.Subject = "[eIncoming] - Failed 100% Inspection on " & PartNumber & ""
    oMail.Body = "Hi All," & vbCrLf & vbCrLf & "Please review " & PartNumber & " and feedback to supplier for repeating reject." & vbCrLf & vbCrLf & "Regards, " & vbCrLf & "abc"
    oMail.To = "abc@abc.com"
    oMail.Send
    Set oMail = Nothing
    Set oApp = Nothing
    Attached Thumbnails Attached Thumbnails apple.JPG  

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Requires HTML code tags to construct table structure and Outlook automation to send, not DoCmd.SendObject. Review http://www.codekabinett.com/rdumps.p...ss-VBA-outlook and https://excellenttips.wordpress.com/...rosoft-access/
    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.

  3. #3
    onlylonely is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    May 2017
    Posts
    110
    Quote Originally Posted by June7 View Post
    Requires HTML code tags to construct table structure and Outlook automation to send, not DoCmd.SendObject. Review http://www.codekabinett.com/rdumps.p...ss-VBA-outlook and https://excellenttips.wordpress.com/...rosoft-access/
    Hi June,

    Thanks for your reply.
    I'm following exactly one of those. But still couldn't get it.
    Can you please help me to take a look?

    Code:
    Option Compare DatabasePublic Sub SendMail()
    
    
        Dim myMail      As Outlook.MailItem
        Dim myOutlApp   As Outlook.Application
        Dim att         As Outlook.Attachment
    
    
        ' Creating an Outlook-Instance and a new Mailitem
        Set myOutlApp = New Outlook.Application
        Set myMail = myOutlApp.CreateItem(olMailItem)
    
    
        With myMail
            ' setting the recipient
            .To = "abc@abc.com"
            
            ' defining a subject for the mail
            .Subject = "An email with CSS formatting and embedded image created by Outlook automation"
            
            
            <html>
            <body>
            <p> Morning world! </p>
            </body>
            </html>
            ' Setting BodyFormat and body-text of the mail
            .BodyFormat = olFormatHTML
            .HTMLBody = GetHTMLText
            
            ' Adding an attachment from filesystem
            'Set att = .Attachments.Add("D:\tmp\DummyBarcode.jpg")
            ' Setting the PR_ATTACH_CONTENT_ID property to "DummyBarcode.jpg"
            'att.PropertyAccessor.SetProperty "http://schemas.microsoft.com/mapi/proptag/0x3712001F", "DummyBarcode.jpg"
                    
            ' sending the mail
            .Send
            ' You can as well display the generated mail by calling the Display-Method
            ' of the Mailitem and let the user send it manually later.
        End With
    
    
        ' terminating the Outlook-Application instance
        myOutlApp.Quit
    
    
        ' Destroy the object variables and free the memory
        Set myMail = Nothing
        Set myOutlApp = Nothing
    
    
    End Sub
    Attached Thumbnails Attached Thumbnails test.JPG  

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    If you put the HTML code in VBA then it all must be enclosed within quote marks and populate a variable as shown in the second link.

    strHTML = "<html><body><p> Morning world! </p></body></html>"

    Your code is mixing the two examples. GetHTMLText is from the first link. Pick one to follow.
    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.

  5. #5
    onlylonely is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    May 2017
    Posts
    110
    Quote Originally Posted by June7 View Post
    If you put the HTML code in VBA then it all must be enclosed within quote marks and populate a variable as shown in the second link.

    strHTML = "<html><body><p> Morning world! </p></body></html>"

    Your code is mixing the two examples. GetHTMLText is from the first link. Pick one to follow.
    Hi June,

    I'm now stuck with something.
    My expectation is like below attachment send via email.
    But it only appear to have 1 row when send to my email.
    Appreciate if you could take a look on it.
    Attached Thumbnails Attached Thumbnails apple2.JPG  
    Attached Files Attached Files

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    This works for me:

    Code:
    Dim myMail      As Outlook.MailItem
    Dim myOutlApp   As Outlook.Application
    Dim att         As Outlook.Attachment
    Dim strHTML As String
    Dim rst As DAO.Recordset
    Set myOutlApp = New Outlook.Application
    Set myMail = myOutlApp.CreateItem(olMailItem)
    Set rst = CurrentDb.OpenRecordset("SELECT PartNumber, Qty FROM TABLE1", dbOpenSnapshot)
    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![PartNumber] & "</td>"
            strHTML = strHTML & "<td style='padding: 10px; border-style: solid; border-color: #ccc; border-width: 1px 1px 0 0;'>" & rst![Qty] & "</td></tr>"
            rst.MoveNext
        Loop
        .HTMLBody = "<!DOCTYPE html><html><body><table><tr><td>PartNumber</td><td>Qty</td></tr>" & strHTML & "</table></body></html>"
        .To = "abc@abc.com"
        .Subject = "An email with CSS formatting and embedded image created by Outlook automation"
        .BodyFormat = olFormatHTML
    '    .send
        .display
    End With
    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.

  7. #7
    onlylonely is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    May 2017
    Posts
    110
    Quote Originally Posted by June7 View Post
    This works for me:

    Code:
    Dim myMail      As Outlook.MailItem
    Dim myOutlApp   As Outlook.Application
    Dim att         As Outlook.Attachment
    Dim strHTML As String
    Dim rst As DAO.Recordset
    Set myOutlApp = New Outlook.Application
    Set myMail = myOutlApp.CreateItem(olMailItem)
    Set rst = CurrentDb.OpenRecordset("SELECT PartNumber, Qty FROM TABLE1", dbOpenSnapshot)
    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![PartNumber] & "</td>"
            strHTML = strHTML & "<td style='padding: 10px; border-style: solid; border-color: #ccc; border-width: 1px 1px 0 0;'>" & rst![Qty] & "</td></tr>"
            rst.MoveNext
        Loop
        .HTMLBody = "<!DOCTYPE html><html><body><table><tr><td>PartNumber</td><td>Qty</td></tr>" & strHTML & "</table></body></html>"
        .To = "abc@abc.com"
        .Subject = "An email with CSS formatting and embedded image created by Outlook automation"
        .BodyFormat = olFormatHTML
    '    .send
        .display
    End With
    Thanks June! This is what i'm looking for!
    But how to make the PartNumber and Qty inside the table ?
    I mean inside the box.
    Attached Thumbnails Attached Thumbnails apple2.JPG  

  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,926
    The headers are within the table, just not formatted. Use the same formatting codes in the <td> tag if you want.
    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
    onlylonely is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    May 2017
    Posts
    110
    Quote Originally Posted by June7 View Post
    The headers are within the table, just not formatted. Use the same formatting codes in the <td> tag if you want.
    Thanks June7 ! I got it !

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

Similar Threads

  1. Replies: 3
    Last Post: 09-30-2016, 04:49 PM
  2. Send email using CDO, get email addresses from table
    By marvinac1 in forum Programming
    Replies: 3
    Last Post: 12-22-2014, 12:54 PM
  3. How can I send an email from access???
    By Asma in forum Programming
    Replies: 2
    Last Post: 12-07-2011, 07:49 AM
  4. VBA to Send email from Access
    By ped in forum Access
    Replies: 3
    Last Post: 08-11-2011, 05:37 PM
  5. Send email from Access DB Table
    By skaswani in forum Programming
    Replies: 3
    Last Post: 12-18-2010, 04:23 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