Results 1 to 3 of 3
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    670

    Send Outlook Email With Body As recordset results

    Hi -



    I know I can use the below code to populate a textbook from a recordset (i.e. query results)
    Code:
    Set rs = db.OpenRecordset("qryData")
    If Not (rs.BOF And rs.EOF) Then
      rs.MoveLast
      rs.MoveFirst
      While (Not rs.EOF)
        Me.txtbox1 = Me.txtbox1 & vbCrLF & Space(7) & rs![public systems.entity number] & " - " & rs![public systems.employee id] & vbCrLF
        rs.MoveNext
      Wend
    End If
    However, how can I adapt this (or if someone has an easier method I'm down, to use the data from the query above in the body of my outlook email?

    This is how I currently populate an outlook email from access vba
    Code:
    Dim oApp As Outlook.Application
    Dim oMail As MailItem
    Set oApp = CreateObject("Outlook.application")
    
    Set oMail = oApp.CreateItem(olMailItem)
    oMail.Subject = "Subject"
    oMail.To = "SendTo"
    oMail.Body = "Body of Email"
    oMail.Send
    
    Set oMail = Nothing
    Set oApp = Nothing

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Just reference the textbox. Or put the recordset looping code within a function and call the function from the email code. Or put the looping code directly in the email procedure.

    If you want to do something fancy with the concatenated data, like make it look like a table with borders and text formatting, use HTML code tags and set oMail.HTMLBody.
    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
    Wayne is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2019
    Location
    Toronto, Canada
    Posts
    6
    I had the same idea - needed the details in the body of the email. I had a lot of trouble getting it to work, so I took a different route. I set up a report, output it to HTML, and placed it in the body of the email. It worked perfectly.

    Check out this thread:

    https://www.accessforums.net/showthread.php?t=76869

    Hope it helps.

    Wayne

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. Replies: 4
    Last Post: 07-12-2018, 05:38 AM
  3. send email with attached image in body
    By trevor40 in forum Programming
    Replies: 5
    Last Post: 02-14-2014, 01:17 AM
  4. Send Report as body of email
    By chris.williams in forum Reports
    Replies: 3
    Last Post: 09-15-2012, 09:43 AM
  5. Send in Email Body vice Attachment
    By cassidym in forum Programming
    Replies: 2
    Last Post: 10-20-2010, 06:21 AM

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