Sending report as HTML Body of e-mail

C

cyb3rwolf

Hello. I have a form where i have a button set up to send the contents of a
report in the body of an e-mail. The problem i run into is that if the
report is more than one page, it will only show the first page in the body of
an e-mail with links to the other pages at the bottom of the e-mail, which
cannot be accessed. Is there a way to code it where the whole report would
be one page to solve my little problem? Here is the code i currently have:

Public Sub olSendRpt(strTo As String, strBody As String, strSubject As
String, strReportName As String)
Dim strFileName As String, intFile As Integer, strLine As String,
strTemplate As String
Dim objOutlk 'Outlook
Dim objMail 'Email item
Dim strMsg
strFileName = Environ("Temp") & "\rep_temp.html"

If Len(Dir(strFileName)) > 0 Then
Kill strFileName
End If
DoCmd.OutputTo acOutputReport, strReportName, acFormatHTML, strFileName

intFile = FreeFile
Open strFileName For Input As #intFile
Do While Not EOF(intFile)
Line Input #intFile, strLine
strTemplate = strTemplate & vbCrLf & strLine
Loop
Close #intFile
strMsg = strTemplate
Set objOutlk = CreateObject("Outlook.Application")
Set objMail = objOutlk.createitem(olMailItem)
objMail.To = strTo
objMail.CC = ""
objMail.subject = strSubject
objMail.HTMLbody = strMsg
objMail.Display

Set objMail = Nothing
Set objOutlk = Nothing

End Sub
 
N

NKTower

I copied just the portion of your code that generates the HTML and ran it
against a report that emits 7 pages. I then went and found the pages in the
folder pointed to by the TEMP environment variable and found the output. The
files were named

rep_temp.html
rep_tempPage2.html
rep_tempPage3.html
....
rep_tempPage7.html


==================================
IMPORTANT: In the text that follows, I have replaced the 'less than'
character with the left curly brace since I don't know if this board will
pass the less than character through without complaint. It probably will,
but I'd rather not chance it. In same way, I have replaced the greater than
character with the right curley brace.
===================================


I examined the source for the first file - rep_temp.html
Four lines up from the bottom is "{/TABLE}" You need this line
Throw away the next lines (a blank line),line starting with {A, and {/HTML}
The {A line is the one that puts out the links. The {/HTML} is the one that
acts as EOF.

You may keep the blank line, but throw out the line starting with {A through
the end of file.

To be able to do this you are going to have to "look ahead" several lines in
your code.


For a deluxe version you can show where the page breaks were by putting out
a blank line, a horizontal rule line, and another blank with this...

{P}{HR}{P}

{P} is a paragraph break (an empty line), HR is a Horizontal Rule - the
width of the page. The second {P is to give you a bit of blank space below
the line.

Now loop through the subsequent files in order. For each, delete the first
6 lines, such that the first line you keep starts with "{TABLE"



When done, write {/HTML} as the last line of your consolidated output file.

That it worked here. I've added a new tool to my toolbox.


:

} Hello. I have a form where i have a button set up to send the contents of
a
} report in the body of an e-mail. The problem i run into is that if the
} report is more than one page, it will only show the first page in the body
of
} an e-mail with links to the other pages at the bottom of the e-mail, which
} cannot be accessed. Is there a way to code it where the whole report would
} be one page to solve my little problem? Here is the code i currently have:
}
} Public Sub olSendRpt(strTo As String, strBody As String, strSubject As
} String, strReportName As String)
} Dim strFileName As String, intFile As Integer, strLine As String,
} strTemplate As String
} Dim objOutlk 'Outlook
} Dim objMail 'Email item
} Dim strMsg
} strFileName = Environ("Temp") & "\rep_temp.html"
}
} If Len(Dir(strFileName)) } 0 Then
} Kill strFileName
} End If
} DoCmd.OutputTo acOutputReport, strReportName, acFormatHTML, strFileName
}
} intFile = FreeFile
} Open strFileName For Input As #intFile
} Do While Not EOF(intFile)
} Line Input #intFile, strLine
} strTemplate = strTemplate & vbCrLf & strLine
} Loop
} Close #intFile
} strMsg = strTemplate
} Set objOutlk = CreateObject("Outlook.Application")
} Set objMail = objOutlk.createitem(olMailItem)
} objMail.To = strTo
} objMail.CC = ""
} objMail.subject = strSubject
} objMail.HTMLbody = strMsg
} objMail.Display
}
} Set objMail = Nothing
} Set objOutlk = Nothing
}
} End Sub
}
}
 

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