title: Access VBA To Send Query Results to Outlook Email in Table Format
body: <p>I would like to send an e-mail with outlook based on the query results from my table but with table formatting (in the body). For some reason the code is only outputting the last record in the table to the e-mail body, instead of looping and adding all 3 records. </p>
  
  <p>Any suggestions, or a better way to code this?</p>
  
  <pre><code>Public Sub NewEmail()
  'On Error GoTo Errorhandler
  
      Dim olApp As Object
      Dim olItem As Variant
      Dim olatt As String
      Dim olMailTem As Variant
      Dim strSendTo As String
      Dim strMsg As String
      Dim strTo As String
      Dim strcc As String
      Dim rst As DAO.Recordset
      Dim rs As DAO.Recordset
      Dim db As DAO.Database
      Dim qry As DAO.QueryDef
      Dim fld As Field
      Dim varItem As Variant
      Dim strtable As String
      Dim rec As DAO.Recordset
      Dim strqry As String
  
      strqry = "SELECT * From Email_Query"
  
      strSendTo = "test@email.com"
      strTo = ""
      strcc = ""
  
      Set olApp = CreateObject("Outlook.application")
      Set olItem = olApp.CreateItem(olMailTem)
  
      olItem.Display
      olItem.To = strTo
      olItem.CC = strcc
      olItem.Body = ""
      olItem.Subject = "Test E-mail"
  
      Set db = CurrentDb
      Set rec = CurrentDb.OpenRecordset(strqry)
      If Not (rec.BOF And rec.EOF) Then
         rec.MoveLast
          rec.MoveFirst
          intCount = rec.RecordCount
              For intLoop = 1 To intCount
                  olItem.HTMLBody = "&lt;HTML&gt;&lt;body&gt;" &amp; _
                  "&lt;table border='2'&gt;" &amp; _
                  "&lt;tr&gt;" &amp; _
                  "&lt;th&gt; Request Type &lt;/th&gt;" &amp; _
                  "&lt;th&gt; ID &lt;/th&gt;" &amp; _
                   "&lt;th&gt; Title &lt;/th&gt;" &amp; _
                    "&lt;th&gt; Requestor Name &lt;/th&gt;" &amp; _
                     "&lt;th&gt; Intended Audience &lt;/th&gt;" &amp; _
                     "&lt;th&gt; Date of Request&lt;/th&gt;" &amp; _
                     "&lt;th&gt; Date Needed &lt;/th&gt;" &amp; _
                     "&lt;/tr&gt;" &amp; _
                     "&lt;tr&gt;" &amp; _
                        "&lt;td&gt;" &amp; rec("Test1") &amp; "&lt;/td&gt;" &amp; _
                        "&lt;td&gt;" &amp; rec("Test2") &amp; "&lt;/td&gt;" &amp; _
                        "&lt;td&gt;" &amp; rec("Test3") &amp; "&lt;/td&gt;" &amp; _
                        "&lt;td&gt;" &amp; rec("Test4") &amp; "&lt;/td&gt;" &amp; _
                        "&lt;td&gt;" &amp; rec("Test5") &amp; "&lt;/td&gt;" &amp; _
                        "&lt;td&gt;" &amp; rec("Test6") &amp; "&lt;/td&gt;" &amp; _
                        "&lt;td&gt;" &amp; rec("Test7") &amp; "&lt;/td&gt;" &amp; _
                        "&lt;/tr&gt;" &amp; _
                       "&lt;body&gt;&lt;HTML&gt;"
                  rec.MoveNext
              Next intLoop
      End If
  
      MsgBox "E-mail Sent"
      Set olApp = Nothing
      Set olItem = Nothing
  
  Exit_Command21_Click:
      Exit Sub
  ErrorHandler:
      MsgBox Err.Description, , Err.Number
      Resume Exit_Command21_Click
  End Sub
  </code></pre>