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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Reports In Email Message

Status
Not open for further replies.

egobbitz

Programmer
Oct 18, 2002
47
US
I am trying to send an email to a distribution list that embeds three access reports. I am able to do this, but the reports come out as links instead of embedded objects. Can anyone help me figure out what I am doing wrong so that these reports will come out as objects embedded in the email, and not shortcuts to the messages on the server?

Here is my code...
Public Function createReports()

Dim filename1 As String, filename2 As String, filename3 As String

Dim d As Date
Dim datestr As String
d = Now()
datestr = CStr(d)


filename1 = "J:\RejectRepair\EntryStats.rtf"
filename2 = "J:\RejectRepair\ProcTypes.rtf"
filename3 = "J:\RejectRepair\DailyEncode.rtf"



DoCmd.OutputTo acOutputReport, "Entries Report by Time", acFormatRTF, filename1
DoCmd.OutputTo acOutputReport, "Process Types Report", acFormatRTF, filename2
DoCmd.OutputTo acOutputReport, "Power Encoded Daily Report", acFormatRTF, filename3

Dim appOutLook As Variant
Dim MailOutLook As Variant

Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
MailOutLook.Save


With MailOutLook
.To = distNames()
.Subject = "Daily Reject Statistics " & d
.Attachments.Add filename1, olByValue, 1, "EntryStats.rft"
.Attachments.Add filename2, olByValue, 1, "ProcTypes.rtf"
.Attachments.Add filename3, olByValue, 1, "DailyEncode.rtf"
.Display
End With


End Function
 
egobbitz

This is the code I use for attaching reports by e-mail. Hope it goes someway to solving your problem. Your files should be embedded using this code

Function NewMailMessage()
Dim ol As New Outlook.Application
Dim ns As Outlook.NameSpace
Dim newMail As Outlook.MailItem

'Return a reference to the MAPI layer.
Set ns = ol.GetNamespace("MAPI")

'Create a new mail message item.
Set newMail = ol.CreateItem(olMailItem)
With newMail
'Add the subject of the mail message.
.Subject = "Progress Report and Invoicing by Day Report"
'Create some body text.
.Body = "Jackie" & vbCrLf & vbCrLf & "Please find enclosed the Progress Report and Invoicing by Day Report for today" & vbCrLf & vbCrLf & "Regards" & vbCrLf & vbCrLf & "Elise" & vbCrLf & vbCrLf

'Add a recipient and test to make sure that the
'address is valid using the Resolve method.
With .Recipients.Add("Jackie")
.type = olTo
If Not .Resolve Then
MsgBox "Unable to resolve address.", vbInformation
Exit Function
End If
End With

With .Recipients.Add("Emma")
.type = olTo
If Not .Resolve Then
MsgBox "Unable to resolve address.", vbInformation
Exit Function
End If
End With
'Attach a file as a link with an icon.
With .Attachments.Add("C:\Figures\TodaysProgressReport.snp")
.DisplayName = "Progress Report"
End With
With .Attachments.Add("C:\Figures\InvoicingByDay.snp")
.DisplayName = "InvoicingbyDayReport"
End With

'Send the mail message.
.Send

End With

'Release memory.
Set ol = Nothing
Set ns = Nothing
Set newMail = Nothing
End Function
 
Elise,

I'm not sure how big of a deal this is, but I'm not seeing the .Resolve option, only .ResolveAll, when adding recipients. Is there something that I'm missing? Is there a difference at all b/w the two methods? I tried just typing .recipients.resolve and i got an error. (Object does not support this property or method)

Set olObj = New Outlook.Application
Set objEmail = olObj.CreateItem(olMailItem)

with objemail
.recipients.Add strRec
End With

I have Outlook 9.0 referenced and strRec is a string Variable holding the name of person to add.

Thanks, Janel

vba 6.0,
a2k 9.0.3821 sr-1
 
Thanks for all the help guys. I still have one problem though. Does outlook have to be active for this to work. I am getting an error code when I try to run this code without outlook active.

Here is my error.

Runtime error -2113732605 (82030003)

Here is the line of my code that causes the problem.

Set MailOutlook = appOutLook.CreateItem(olMailItem)

Any help would be appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top