HTML report in the body of mail (1 Viewer)

P

Pun_it

Guest
Hi,
I tried to search for my problem, but somehow I could not locate exactly what I needed.

I am generating a report using sendobject in html format, this saves the file in the specified location.

What i then want to do is to use this file in the body of an e-mail.
I am not very conversant with how to play with html files.

Would be grateful if somebody could help :eek:
 

Hayley Baxter

Registered User.
Local time
Today, 06:21
Joined
Dec 11, 2001
Messages
1,607
The following code will send your chosen report as an email and it will be
included in the message block instead of an attachment.

Code:
Function exporthtml()

Dim strline, strHTML

 Dim OL As Outlook.Application
  Dim MyItem As Outlook.MailItem

  Set OL = New Outlook.Application
  Set MyItem = Outlook.Application.CreateItem(olMailItem)
  
  DoCmd.OutputTo acOutputReport, "Catalog", acFormatHTML,
"C:\myreport.html"
  
  Open "C:\myreport.html" For Input As 1
  Do While Not EOF(1)
    Input #1, strline
    strHTML = strHTML & strline
  Loop
  Close 1
  ' If OL2002 set the BodyFormat
  If Left(OL.Version, 2) = "10" Then
    MyItem.BodyFormat = olFormatHTML
  End If
  MyItem.HTMLBody = strHTML
  MyItem.Display

End Function

The above code help you export the Catalog report in Northwind.mdb sample
database so you can try it out there first as a test then change the coding slightly to match the field / report names in your own database.

HTH
Hay
 
P

Pun_it

Guest
Thanks a lot Mr. Baxter for your response. However, when I tried your suggestion, it comes up with a compile error:User defined type not defined.

Is it a library reference problem?

Would be glad if you could take me through with this one.

Am using Access + Outlook 2002.

Best Regards,
 
Last edited:

Hayley Baxter

Registered User.
Local time
Today, 06:21
Joined
Dec 11, 2001
Messages
1,607
Pun_it said:
Is it a library reference problem?

Yep, certainly sounds that way to me.

Seeing as you were able to identify the problem, I assume you know how to correct this issue? If not all you need to do is

On the Tools menu, click References.
Click to select the object library that is missing.

Hay
 
P

Pun_it

Guest
Yes. I have added Outlook 10.0 library and that has solved the problem.

Sincere Thanks & Regards,
Puneet Mehta
 

BrianB75

Registered User.
Local time
Today, 00:21
Joined
Aug 27, 2004
Messages
43
The above solution appears to work for me but some elements of the report are not being displayed. I attached the test report in a snapshot format and also the HTML output. I cannot figure out why the two horizontal lines and the picture are not outputting. Could someone give me a heads up as to why as my knowledge of HTML is very limited?:confused:

Thanks in advance.
 

Attachments

  • Snapshot Test Report.JPG
    Snapshot Test Report.JPG
    55 KB · Views: 1,613
  • HTML Test Report.JPG
    HTML Test Report.JPG
    45.5 KB · Views: 1,523

Hayley Baxter

Registered User.
Local time
Today, 06:21
Joined
Dec 11, 2001
Messages
1,607
Hi Brian

I'm afraid that exporting a report from access does not keep the formatting as it is in access itself, that is unless you export to PDF or snapshot viewer. The problem with snapshot viewer is that it's not everyone that has this installed on their pc. I think I posted a sample on here a while back of exporting an Access report to word that keeps the formatting as it is in access using vba code.it should still be available for download on here if you do a search for it.

Hay
 

BrianB75

Registered User.
Local time
Today, 00:21
Joined
Aug 27, 2004
Messages
43
Snapshot viewer actually isn't a problem as everyone in our office has it installed. The issue is that the requirements for this report state that it needs to be displayed in the body of the e-mail and not as an attachment.

I thought about the pdf route but I don't think I could pull that into the body of the e-mail.

The picture itself is not that important and someone here showed me a cheap, but effective way of adding the lines. Just create a text field on the report containing nothing but underscores ___. This works but I was hoping to use some of the other formatting options from the reports.

Any ideas? Could I export the report as a jpeg and then insert that somehow into the body of the e-mail?

Thanks again.
 

BrianB75

Registered User.
Local time
Today, 00:21
Joined
Aug 27, 2004
Messages
43
I ended up using underscores for the lines and it worked out well. The wired thing is that when the code exports the html file the formatting looks fine, its when it imports it into the e-mail that things start acting up. It appears that it is adding double spaces between all of the lines.

The code I used is almost identical to what was posted, besides the names being changed. I cannot seem to find out why these double spaces are being used.

Any ideas?

Thanks again.
 

hortizjr59

Registered User.
Local time
Today, 01:21
Joined
Sep 6, 2011
Messages
30
I tried using this code with a few mods in my database but keep getting a compiler syntax error:

I am using the code as follows:
Private Sub Command135_Click()
Dim strline, strHTML
Dim OL As Outlook.Application
Dim MyItem As Outlook.MailItem
Set OL = New Outlook.Application
Set MyItem = Outlook.Application.CreateItem(olMailItem)

strWhere = "[Improvement No] = " & Me.[Improvement No]
DoCmd.OutputTo acOutputReport, "ReportEmailNoticeofAssigned", acFormatHTML,
"C:\Documents and Settings\hortiz\My Documents\Hector\myreport.html"

Open "C:\Documents and Settings\hortiz\My Documents\Hector\myreport.html" For Input As 1
Do While Not EOF(1)
Input #1, strline
strHTML = strHTML & strline
Loop
Close 1
' If OL2002 set the BodyFormat
If Left(OL.Version, 2) = "10" Then
MyItem.BodyFormat = olFormatHTML
End If
MyItem.HTMLBody = strHTML
MyItem.Display
End Sub
 

Users who are viewing this thread

Top Bottom