Results 1 to 4 of 4
  1. #1
    chris.williams is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    94

    Send Report as body of email

    I've seen a few posts here and online about how to send an email with a report as the body via HTML file.



    I have some code that is supposed to do it, but it only sends the HTML file as an attachment, not the body. How do you populate the body with and HTML file?

    Code:
    DoCmd.OutputTo acOutputReport, "rpt_approvalrequest", , "c:\temp\approvalrequest.htm"
    
    Dim objOutlook As Object
    Dim objEmail As Object
    Set objOutlook = CreateObject("Outlook.application")
    UserName = "info@company.com"
    SubjectText = "Approval Request: " & [TempVars]![CurrentSR]
    EmailTemplate = "C:\temp\messagetemplate.oft"
    Set objEmail = objOutlook.CreateItemFromTemplate(EmailTemplate)
    
    With objEmail
    .To = UserName
    .Subject = SubectText
    .Body = "The body doesn't matter, just the attachment"
    .Attachments.Add "C:\temp\approvalrequest.htm"
    .Display
    '.Send 
    '.ReadReceiptRequested
    End With

  2. #2
    chris.williams is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    94
    I don't know what I did, but this code seems to have done the trick. Not much different from the above. If anyone has some insight, I'd appreciate it. Thanks...

    Code:
    Dim varApprovalRequest, varReportName, varSendTo, varHTMLBody, varEmailTemplate As String
    varApprovalRequest = "c:\temp\approvalrequest.htm"
    varReportName = "rpt_approvalrequest"
    varSendTo = "me@company.com"
    varEmailTemplate = "c:\temp\messagetemplate.oft"
    
    DoCmd.OutputTo acOutputReport, varReportName, acFormatHTML, varApprovalRequest
    
    
    Dim objOutlook, objEmail As Object
    Set objOutlook = CreateObject("Outlook.application")
    UserName = varSendTo
    SubjectText = "Approval Request: " & [TempVars]![CurrentSR]
    EmailTemplate = varEmailTemplate
    Set objEmail = objOutlook.CreateItemFromTemplate(EmailTemplate)
    With objEmail
    .To = UserName
    .Subject = SubectText
    '.Body = "The body doesn't matter, just the attachment"
    .HTMLBody = varHTMLBody
    .Attachments.Add varApprovalRequest
    .Display
    '.Send - this didn't work on my setup but .Display did
    '.ReadReceiptRequested
    End With

  3. #3
    ashu.doc is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jul 2012
    Posts
    124
    Quote Originally Posted by chris.williams View Post
    I don't know what I did, but this code seems to have done the trick. Not much different from the above. If anyone has some insight, I'd appreciate it. Thanks...

    Code:
    Dim varApprovalRequest, varReportName, varSendTo, varHTMLBody, varEmailTemplate As String
    varApprovalRequest = "c:\temp\approvalrequest.htm"
    varReportName = "rpt_approvalrequest"
    varSendTo = "me@company.com"
    varEmailTemplate = "c:\temp\messagetemplate.oft"
    
    DoCmd.OutputTo acOutputReport, varReportName, acFormatHTML, varApprovalRequest
    
    
    Dim objOutlook, objEmail As Object
    Set objOutlook = CreateObject("Outlook.application")
    UserName = varSendTo
    SubjectText = "Approval Request: " & [TempVars]![CurrentSR]
    EmailTemplate = varEmailTemplate
    Set objEmail = objOutlook.CreateItemFromTemplate(EmailTemplate)
    With objEmail
    .To = UserName
    .Subject = SubectText
    '.Body = "The body doesn't matter, just the attachment"
    .HTMLBody = varHTMLBody
    .Attachments.Add varApprovalRequest
    .Display
    '.Send - this didn't work on my setup but .Display did
    '.ReadReceiptRequested
    End With

    Hi Chris
    I have 2 questions -
    1. how to save the report as a separate file from access application. So that the user of the application can save the report in which ever format they like and print it later on from same or different computer so that they dont have to take whole application with them to print the report out.
    2. the procedure which you have mentioned about emailing the report, where do I have to put this code?

    Many thanks.

  4. #4
    chris.williams is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    94
    To save the report as a file, you can use this code:

    Code:
    DoCmd.OutputTo acOutputReport, varReportName, acFormatHTML, varApprovalRequest
    You would want to change the acFormat to your preferred format such as PDF, RTF, HTML or something else.

    To execute this code, you could assign it to an event such as "On Click" for a button or "On Change" for a dropdown.

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

Similar Threads

  1. Email report as body of email (RTF)
    By TheDeceived in forum Programming
    Replies: 4
    Last Post: 07-23-2012, 06:39 AM
  2. Email report as body of email
    By chrish20202 in forum Programming
    Replies: 6
    Last Post: 01-15-2012, 07:23 PM
  3. Replies: 1
    Last Post: 05-23-2011, 08:07 AM
  4. Email from report to Email body
    By Ehmke66 in forum Programming
    Replies: 4
    Last Post: 01-03-2011, 01:06 PM
  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