Trouble displaying a report in the body of an email. Access2000

D

DBenedict

I have a small report (2" x 5" when printed) that when opened, shows the
current records in a form. I have to forward the report to others via email.

Instead of an attaching the report, I want to display the report as the body
of the Outlook email. The small 2x5" report visible in the email.

I'll use a button on the form to Open Outlook and output the report.

A previous attempt got Outlook to open and a brief screen message saying
"outputting report to ..." and then nothing. Just an open email with
nothing in the body.

After trying a few other things that didn't work, I stopped with this
attached to the button.

Private Sub SendMessage_Click()

ap_CreateOLMailItem

End Sub

I have this saved in the module.

Option Compare Database
Option Explicit

Public olkApp As Outlook.Application
Public olkNameSpace As Outlook.NameSpace
---------------------------------------------------
Sub ap_CreateOLMailItem()

Dim objMailItem As Outlook.MailItem
Dim myReport As Report

myReport.NAME = "Audit Results"

Set olkApp = New Outlook.Application

Set olkNameSpace = olkApp.GetNamespace("MAPI")
Set objMailItem = olkApp.CreateItem(olMailItem)

With objMailItem
DoCmd.OutputTo acOutputReport, myReport, acFormatHTML,
CurrentProject.Path & "\myReport.html"
.Display
End With

Set objMailItem = Nothing
Set olkNameSpace = Nothing
Set olkApp = Nothing

End Sub

"Audit Results" is the name of the report I want to insert it into the body.


I have read several posts of similar content, but as always, I want to do
things differently. I tried to piece code together for the parts that I want.

I have had numerous errors and for each I overcome, there is another.

I'd get errors here (myReport.NAME = "Audit Results") and here
(DoCmd.OutputTo acOutputReport, myReport, acFormatHTML, CurrentProject.Path &
"\myReport.html")

Any suggestions to get me on the right track?
 
D

DBenedict

OK, that line of code it did work. But it only seems to work in .txt?
rtf, html, snp comes through as junk. Any idea why? I also lost my Outlook
Signature on newmail but I'll keep trying it both.

I made a couple modifications to the original code and once again I can get
Outlook to open my email but without the report. On the DoCmd line I added
the , AutoStart = True.

Now Outlook opens and the Report opens, separately. Looks like the
connection between the Report and Outlook is missing. This makes sense why I
saw "Outputting report...." and then nothing. The default for AutoStart is
False.

What works. Outlook opens. The report opens with the correct data. I'm
trying .rtf at this point but I'd like to use .snp so it looks like the
report looks when printed.

This is what I have now.

On the botton.
Private Sub SendMessage_Click()


ap_CreateOLMailItem ("Audit Results")


End Sub

In the module.
Option Compare Database
Option Explicit

Public olkApp As Outlook.Application
Public olkNameSpace As Outlook.NameSpace

Sub ap_CreateOLMailItem(myReport As String)

Dim objMailItem As Outlook.MailItem

Set olkApp = New Outlook.Application

Set olkNameSpace = olkApp.GetNamespace("MAPI")
Set objMailItem = olkApp.CreateItem(olMailItem)

With objMailItem
DoCmd.OutputTo acOutputReport, myReport, acFormatRTF,
CurrentProject.Path & "\myReport.rtf", True
.Display
End With

Set objMailItem = Nothing
Set olkNameSpace = Nothing
Set olkApp = Nothing

End Sub

I'm missing something to connect the email and the report. The DoCmd line
somewhere?
 
A

Alex Dybenko

Hi,
one thing is missing in your code. after:
DoCmd.OutputTo acOutputReport, myReport, acFormatRTF, CurrentProject.Path &
"\myReport.rtf", True

you have to read myReport.rtf, then make sure that new outlook item switched
to RTF format and pass it string, which you read from myReport.rtf.

else you can send in HTML, but then either save report as html, or convert
rtf to html, I am using this library for such purpose:
http://www.pilotltd.com/eng/irun/index.html

--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top