By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,025 Members | 1,292 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,025 IT Pros & Developers. It's quick & easy.

E-mailing a Report in HTML

P: n/a
Is there a way to skip the format selection when e-mailing reports?
Maybe in the VB coding? I want them to always be sent in an HTML
format.
Any information is helpful. Thanks.

Nov 17 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
microsoft access wrote:
Is there a way to skip the format selection when e-mailing reports?
Maybe in the VB coding? I want them to always be sent in an HTML
format.
Any information is helpful. Thanks.
Are you using SendObject? If so...
DoCmd.SendObject acReport, "ReportName", acFormatHTML, strTo, strCC,
strBCC, "SubjectLine", "BodyText", False
Nov 18 '06 #2

P: n/a


On Nov 18, 4:40 am, salad <o...@vinegar.comwrote:
microsoft access wrote:
Is there a way to skip the format selection when e-mailing reports?
Maybe in the VB coding? I want them to always be sent in an HTML
format.
Any information is helpful. Thanks.Are you using SendObject? If so...
DoCmd.SendObject acReport, "ReportName", acFormatHTML, strTo, strCC,
strBCC, "SubjectLine", "BodyText", False
Yep. That was exactly what I needed. Thanks a lot!

Nov 18 '06 #3

P: n/a
MLH
Salad, I find that acFormatHTML performance is marginal
at best in reproducing HTML facsimiles of Access 97 reports.
So I've taken the liberty of creating the desired HTML string
(very long string) in code, concatenating everything to meet
my own specs.

What I'm missing is how to feed that VLS to the SendObject
method as an attachment to the eMail. Knowing my luck, the
approach I'm taking won't work. But I can't seem to find sufficient
documentation on how to build a template file for the SendObject
method to use to even take a stab at using a template.

Do you know how I can have the SendObject method attach my
own HTML rather than the canned procedure it's using?
Nov 19 '06 #4

P: n/a
microsoft access wrote:
Is there a way to skip the format selection when e-mailing reports?
Maybe in the VB coding? I want them to always be sent in an HTML
format.
Any information is helpful. Thanks.
If you have Windows 2000 or later this sends a report in HTML. It has
been tested in Northwind. Some lines may have been split by news
clients; they will have to be put back together. I think this does not
use any modern functions from this century but I have not tested for
that.

Public Sub SendReportasHTML( _
ByVal ReportName As String, _
ByVal SMTPServer As String, _
ByVal SendUserName As String, _
ByVal SendPassword As String, _
ByVal SendEmailAddress As String, _
ByVal Subject As String, _
ByVal Recipients As String, _
Optional ByVal NumberofPagesAllowed As Long = 10)

Dim Buffer As String
Dim Position As Long
Dim FileNumber As Integer
Dim HTML As String
Dim HTMLFullPath As String
Dim iCfg As Object
Dim iMsg As Object
Dim Skelton As String
Dim TempDirectory As String
Dim Truncate As Long

Set iCfg = CreateObject("CDO.Configuration")
Set iMsg = CreateObject("CDO.Message")

TempDirectory = Environ$("temp")
If Len(TempDirectory) = 0 Then TempDirectory = CurDir$()
TempDirectory = TempDirectory & "\"
Skelton = Format(Now(), "mmmddyyyyhhnnss")
HTMLFullPath = TempDirectory & Skelton & ".html"

DoCmd.OutputTo acOutputReport, ReportName, acFormatHTML, HTMLFullPath

HTMLFullPath = Dir$(TempDirectory & Skelton & "*.html")
While Len(HTMLFullPath) <0 And NumberofPagesAllowed <0
HTMLFullPath = TempDirectory & HTMLFullPath
FileNumber = FreeFile()
Open HTMLFullPath For Binary As #FileNumber
Buffer = String(LOF(FileNumber), vbNullChar)
Get #FileNumber, , Buffer
Close #FileNumber
Position = InStr(Buffer, "</TABLE>")
While Position <0
Truncate = Position
Position = InStr(Truncate + 1, Buffer, "</TABLE>")
Wend
HTML = HTML & Left(Buffer, Truncate + 7)
HTML = HTML & "<hr>"
Kill HTMLFullPath
HTMLFullPath = Dir$()
NumberofPagesAllowed = NumberofPagesAllowed - 1
Wend

If Len(HTMLFullPath) <0 And NumberofPagesAllowed = 0 Then _
HTML = HTML & "<br><b>Partial Report: Additional Pages not Shown"

With iCfg.Fields
..Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
..Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")
= 25
..Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
SMTPServer
..Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")
= 1
..Item("http://schemas.microsoft.com/cdo/configuration/sendusername") =
SendUserName
..Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") =
SendPassword
..Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress")
= SendEmailAddress
..Update
End With
With iMsg
..Configuration = iCfg
..Subject = Subject
..To = Recipients
..HTMLBody = HTML
..Send
End With

SendReportAsHTMLExit:
Close
Set iMsg = Nothing
Set iCfg = Nothing
Exit Sub

SendReportAsHTMLErr:
With Err
MsgBox .Description, vbCritical, "Error " & .Number
End With
Resume SendReportAsHTMLExit

End Sub
Private Sub TestSendReportAsHTML()
SendReportasHTML "Products By Category", "smtp.domain.com",
"fi*******@domain.com", "password", "First Last
<fi*******@domain.com>", "Testing SendReportAsHTML",
"re*******@domain.com"
End Sub

Nov 19 '06 #5

P: n/a
MLH
Looking at your early 2001 post here
http://groups.google.com/group/comp....e=UTF-8&rnum=4

What mods would be necessary to the code you posted (shown below)
to enable specifying and sending of an HTML file or any attachment for
that matter?

Option Explicit

Type MAPIRecip
Reserved As Long
RecipClass As Long
Name As String
Address As String
EIDSize As Long
EntryID As String
End Type

Type MAPIFileTag
Reserved As Long
TagLength As Long
Tag() As Byte
EncodingLength As Long
Encoding() As Byte
End Type

Type MAPIFile
Reserved As Long
Flags As Long
Position As Long
PathName As String
FileName As String
FileType As Long
End Type

Type MAPIMessage
Reserved As Long
Subject As String
NoteText As String
MessageType As String
DateReceived As String
ConversationID As String
Originator As Long
Flags As Long
RecipCount As Long
Recipients As Long
Files As Long
FileCount As Long
End Type

Declare Function MAPISendMail _
Lib "c:\program files\outlook express\msoe.dll" ( _
ByVal Session As Long, _
ByVal UIParam As Long, _
message As MAPIMessage, _
ByVal Flags As Long, _
ByVal Reserved As Long) As Long

Sub SendMailWithOE(ByVal strSubject As String, ByVal strMessage As
String, ByRef
aRecips As Variant)
Dim recips() As MAPIRecip
Dim message As MAPIMessage
Dim z As Long
ReDim recips(LBound(aRecips) To UBound(aRecips))
For z = LBound(aRecips) To UBound(aRecips)
With recips(z)
.RecipClass = 1
If InStr(aRecips(z), "@") <0 Then
.Address = StrConv(aRecips(z), vbFromUnicode)
Else
.Name = StrConv(aRecips(z), vbFromUnicode)
End If
End With
Next z
With message
.NoteText = strMessage
.Subject = strSubject
.RecipCount = UBound(recips) - LBound(aRecips) + 1
.Recipients = VarPtr(recips(LBound(recips)))
End With
MAPISendMail 0, 0, message, 0, 0
End Sub

Sub TestSendMailwithOE()
Dim aRecips(0 To 0) As String
aRecips(0) = "smtp:t...@syspac.com"
SendMailWithOE "Send Mail Through OE", "Sure, you can, Tom!",
aRecips
End Sub
Nov 19 '06 #6

P: n/a
MLH
Oops... I see your answer posted at
http://ffdba.com/downloads/Send_Mail...ok_Express.htm
Sorry. Didn't read far enough, I guess.
Nov 19 '06 #7

P: n/a
MLH wrote:
Salad, I find that acFormatHTML performance is marginal
at best in reproducing HTML facsimiles of Access 97 reports.
So I've taken the liberty of creating the desired HTML string
(very long string) in code, concatenating everything to meet
my own specs.

What I'm missing is how to feed that VLS to the SendObject
method as an attachment to the eMail. Knowing my luck, the
approach I'm taking won't work. But I can't seem to find sufficient
documentation on how to build a template file for the SendObject
method to use to even take a stab at using a template.

Do you know how I can have the SendObject method attach my
own HTML rather than the canned procedure it's using?
Not with SendObject.

You could put the string as the body.

Using Open/Close/Write/Put etc you should be able to write the file to
an HTML file. But to attach you could create an instance of Outlook and
attach the file. On Google Groups (search for Outlook and Attachments
for Group "*Access*") and at Tony Toews site
http://www.granite.ab.ca/access/email.htm you'll find some code to
assist you.

I send out attachments all the time with Outlook and Groupwise. I
create a bunch of PDFs, get other files necessary, and attach the bunch
to the email.

I am hoping, but not expecting, MS to have a better handle on e-mails in
the upcoming version of Access. But MS may keep it as a "roll-your-own"
topic.
Nov 19 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.