Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unexpected HTML result from SendObject 1

Status
Not open for further replies.
Mar 26, 2001
17
US
I've been used DoCmd.SendObject to generate emails in plain text. That's been working out great.

Now, I'm trying to use DoCmd.SendObject to generate an HTML formatted email instead (for looks essentially). If I remember correctly, I've read in the past that DoCmd.SendObject can also generate HTML formatted emails.

However, after writing up the code to test it out, I get an unexpected result. The DoCmd.SendObject did generate an HTML document, however, it end up being an attachment in my Outlook Express instead.

Below is my code (DIM statement, etc, stripped for readability):

Code:
DoCmd.SendObject acSendReport, strReportName, acFormatHTML, strEmailTo, , , strEmailSubject, , True

Although I never written codes with DoCmd.SendObject to generate HTML, I was under the impression that it can generate HTML formatted emails not generate an HTML file to be used as an attachment in your email.

Am I wrong or overlooking something simple and embarrassing? Any input on how I can get DoCmd.SendObject to generate the HTML formatted email I need who be appreciated.

I'm using Access 2003, Outlook Express 6 (with my Mail Sending Format option set to HTML as oppose to Plain text).

Thanks in advance for your input.

-Pete
 
SendObject first outputs the report as a HTML file, then populates the message body and then attaches the html file to the message.

To send the contents of the report as message body, use OutputTo, then good old Open "C:\Temp\YourFile.html" for input, read the contents and dump it to the message body section.

To get the contents you could also use FSO, but I tend to avoid it - personal preference

HTH



[pipe]
Daniel Vlas
Systems Consultant

 
Hi everybody, wanted to ressurrect this thread as I have been trying to get this process to work and having some trouble.

Below is the code I've got to send a report embedded within an email message. I got this from a couple of different places on this forum, so variable declarations without data types are as I found them, and I have substituted real data with fake :)

Code:
Public Function OverdueInspections()

Dim email, emailCC, ref
Dim MsgBody
Dim strline

Open "rptOverDueInspections.html" For Input As 1

While Not EOF(1)
Line Input #1, strline
MsgBody = MsgBody & strline & vbCrLf
Wend

email = "fakename@fakeemailaddress"
emailCC = ""
ref = "Overdue Inspections"

DoCmd.SendObject acSendNoObject, , , email, emailCC, , ref, MsgBody, False

Close #1

End Function

Everything works quite well, except that when I open the email, it shows only the HTML code, not the display as one would see it in a browser (or other HTML type messages I've gotten in Outlook).

Perhaps I am missing something simple but vital here? I am new to this type of procedure and apologize in advance for my ignorance.

Thanks as always,
TWD
 
Hi Thinwhitedude,


have you had any joy in getting this code working as I am after exactly the same solution ! Would be nice to know if you have.

Dave
 
Dave,

Sorry to say I haven't. I ended up writing a VBA procedure to generate the query into body text, which was my main goal as I didn't want to email the info as an attachment.

Perhaps we'll still get a response. . .?

Happy Holidays,
TWD
 
Happy Holidays.... Have a Response for You:

Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim myBodyText As String
Dim Recipient As String

Open "C:\temp\mousetrap.htm" For Input As 1


While Not EOF(1)
Line Input #1, strline
myBodyText = myBodyText & strline & vbCrLf
Wend


Close #1

Set MyOutlook = New Outlook.Application


Set MyMail = MyOutlook.CreateItem(olMailItem)
MyMail.To = "JimBob at Anywhere.com"
MyMail.Subject = "The Mousetrap"
MyMail.HTMLBody = myBodyText


MyMail.Send


End Sub

This should fix your formatting problem.
 
dRahme,

Excellent work, thank you so much! It works great and I have an inbody message I like.

Here's a star. . .

Dave: did you get this?

TWD
 
You're welcome. Thanks for the star. Formatting can be kind of a PITA.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top