Send report as attachment

Marta

Registered User.
Local time
Today, 13:38
Joined
Apr 8, 2011
Messages
16
Hi,

I'm trying to send report called "Harmonogram" as attachment in e-mail. I don't want to use send object method because sometimes I need to sent more files as attachment. Here is the code I use:

Code:
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
Set thereport = CurrentDb.OpenRecordset("Harmonogram")

Email = Me.Email

With objEmail
.To = Email
.Subject = Harmonogram
.Body = text
.Attachments.Add thereport, olByReference, 1, "Harmonogram"
.Display
End With

Set objEmail = Nothing

I have found this code on Internet but there is a problem in line: .Attachments.Add thereport, olByReference, 1, "Harmonogram". It shows me an error message: Data type conversion error. - 3421. Any ideas?

Thank for help.
 
I'm not sure why you have the line "Set thereport = currentdb....". I think you should remove it.

The .Attachments.Add line is usually used to add a file that has already been created. So you need to tell it which file to add.

Take a look at the code in post 5 here.

hth
Chris
 
When I save the report on disk and load it as attachment then it works well, but I don't want to save it on disk because it takes too much time if you need to send e-mail to 200 people. And send object method doesn't allow you to send report and files saved on disk, does it?
 
When I save the report on disk and load it as attachment then it works well, but I don't want to save it on disk because it takes too much time if you need to send e-mail to 200 people. And send object method doesn't allow you to send report and files saved on disk, does it?
I'm not sure what your point is here.

SendObject is a custom method. Yes it allows you to send a single file attachment without actually having to save it. In fact it does save this file to disk temporarily but the method deals with that for you.

The code you are using uses the Outlook Object Model. If you look at Help for the .Add bit you will get details on how Attachments.Add is used. For the source, it say:
"The source of the attachment. This can be a file (represented by the full file system path with a file name) or an Outlook item that constitutes the attachment."

So I don't know of any other way to attach multiple attachments.

Chris
 

Users who are viewing this thread

Back
Top Bottom