Results 1 to 8 of 8
  1. #1
    andyt_2005 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    12

    Export a report to outlook- For dummies.

    Hi all,
    I need a function to export a simple table to outlook, However (this is where i get lost) i want it to be included in the body!
    I understand it will have to be HTML but thats not an issue, th eissue is i have not got a clue where to even start with this!
    I need the user to click a button, then it opens outlook and put the table in the body of the email, includes and email and subject with a short bit of text in the body above the table.
    Thats where i want it to end. i need the user to actually click send.

    Any help hints or tips are greatly welcomed!

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I would start by exporting the query object as an HTML file. I would apply criteria to the query object so it only retrieves one record before exporting to the file. With that, I would use the Source Code as a template in VBA.

    I would use VBA to Automate the creation of an Email. Here is some sample code
    https://www.accessforums.net/forms/c...tml#post225174

  3. #3
    andyt_2005 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    12
    This is the way i was thinking, however it will be used over a large network so the temp file will be created in different places depending on the workstation/user.
    I have found this but like the title of my thread says its a bit too advanced for me !!
    Public Function HtmlNoReportEmail(strTblQryName As
    String)

    Dim olApp As Outlook.Application
    Dim objMail As
    Outlook.MailItem
    Dim strMsg As String
    Dim sqlString As String
    Dim i As
    Integer
    Dim rowColor As String

    Dim rs As ADODB.Recordset
    Set rs =
    New ADODB.Recordset

    sqlString = "SELECT * FROM " & strTblQryName
    & ""
    rs.Open sqlString, CurrentProject.Connection, adOpenKeyset,
    adLockOptimistic

    strMsg = "<table border='1' cellpadding='3'
    cellspacing='3' style='border-collapse: collapse' bordercolor='#111111'
    width='800'>" & _
    "<tr>" & _
    "<td
    bgcolor='#7EA7CC'>&nbsp;<b>Company</b></td>" &
    _
    "<td bgcolor='#7EA7CC'>&nbsp;<b>Last
    Name</b></td>" & _
    "<td
    bgcolor='#7EA7CC'>&nbsp;<b>First Name</b></td>" &
    _
    "<td bgcolor='#7EA7CC'>&nbsp;<b>Job
    Title</b></td>" & _
    "<td
    bgcolor='#7EA7CC'>&nbsp;<b>Business Phone</b></td>"
    & _
    "<td
    bgcolor='#7EA7CC'>&nbsp;<b>City</b></td>" &
    _
    "</tr>"

    i = 0
    Do While Not rs.EOF

    If (i Mod 2 = 0) Then
    rowColor =
    "<td bgcolor='#FFFFFF'>&nbsp;"
    Else
    rowColor = "<td
    bgcolor='#E1DFDF'>&nbsp;"
    End If

    strMsg = strMsg &
    "<tr>" & _
    rowColor & rs.Fields("Company") & "</td>"
    & _
    rowColor & rs.Fields("Last Name") & "</td>" &
    _
    rowColor & rs.Fields("First Name") & "</td>" &
    _
    rowColor & rs.Fields("Job Title") & "</td>" &
    _
    rowColor & rs.Fields("Business Phone") & "</td>" &
    _
    rowColor & rs.Fields("City") & "</td>" &
    _
    "</tr>"

    rs.MoveNext
    i = i + 1
    Loop

    strMsg =
    strMsg & "</table>"

    Set olApp = Outlook.Application
    Set
    objMail = olApp.CreateItem(olMailItem)
    With objMail
    .BodyFormat = olFormatHTML
    .HTMLBody =
    strMsg
    .Recipients.Add "user@email.com"
    .Subject = "Customer
    Data"
    '.Send if you want to send it directly without displaying on
    screen
    .Display
    End With
    Set olApp = Nothing
    Set objMail = Nothing

    End Function

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I do not see any temp file in that code, not that I looked real hard. Why do you need a temp file?

    What is it that you are having trouble with?

  5. #5
    andyt_2005 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    12
    Let me start fresh, I have been at this for so long everything im saying sounds like rubbish to me!
    So what im bascially trying to do is send one coloum from my table to someone.
    The reason i want it to be in the body of the email is so they can write something next to each record and send it back to me.
    this email is to do with reference numbers so i will send the ref. numbers one on each line of text in the email. then they can reply with either complete or outstanding next to each line i send them.
    doesnt need to be formatted just need the data.
    And i really have no idea where to even start with this !
    I have tried google but keep comming up with a blank.
    Access is fairly new to me (about 2 weeks) so VB is something im learning as i go

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Do you HTML that will create a table with one column and one row? Can you get the cell populated with a value?

    If not, create a query that retrieves the data you want to include in the Body of your email. Apply criteria to the query so it only retrieves one record (this is temporary). After you save this query object as outlined, right click the query object and export it as an HTML file.

  7. #7
    andyt_2005 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    12
    yeah can do that fine, Exports exactly how i want it to look. I want a way of doing that automatically and putting it in the body of emails. The idea is the end user will just have to press a button and itll all be done for them.

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Post #2 has some code that you can put behind a click event of a button.

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

Similar Threads

  1. Print just one record for dummies??
    By foofah in forum Reports
    Replies: 4
    Last Post: 02-04-2014, 03:11 PM
  2. export emails from outlook to access
    By johnnyg in forum Import/Export Data
    Replies: 1
    Last Post: 03-05-2013, 12:58 AM
  3. Outlook Export Import Access
    By turk in forum Access
    Replies: 4
    Last Post: 07-17-2012, 07:31 AM
  4. Outlook tasks export
    By eww in forum Programming
    Replies: 5
    Last Post: 11-12-2010, 03:56 PM
  5. Very Easy, but cant find the 'FOR DUMMIES' thread
    By Steven.Allman in forum Queries
    Replies: 1
    Last Post: 03-04-2010, 04:06 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