VBA to send multiple reports as attachments in .rtf file format (1 Viewer)

Essendon

Registered User.
Local time
Today, 03:14
Joined
Oct 25, 2001
Messages
65
Hi all,

I have the following code (taken from a post found in the search facility):

Dim appOutl As Object
Dim MyNameSpace As Object
Dim myemail As Object
Set appOutl = CreateObject("Outlook.Application")
Set MyNameSpace = appOutl.getNameSpace("MAPI")
Set myemail = appOutl.CreateItem(0)


myemail.to = "someone@someone.com"
myemail.Subject = "THIS IS AN AUTOMATED TEST"
myemail.body = "THIS IS THE BODY OF THE EMAIL MESSAGE"
myemail.Attachments.Add "c:\something.txt", 1, 5520, "frunlog.txt"
myemail.Send

I was wondering how I attach a report in ".rtf" format to this email?

For example, a report that I would like to attach I might open from a command button with the following code:

DoCmd.OpenReport "Drivers Report", acPreview, "[ID] = " & Me.ID

I would want to attach this report (filtered with the link criteria) as an rtf attachment to my email message.

I have also noticed that outlook will not automatically send the email, it will remain in the outbox until I click send and receive within outlook. Is there any way to get around this?

Thanks for any help....

Peter
 

simongallop

Registered User.
Local time
Today, 03:14
Joined
Oct 17, 2000
Messages
611
If all that you want to do is send the report by email then look at the DoCmd.SendObject help file. It should all be there including the setting for sending it automaticaly (False at the end of the command)

HTH
 

Essendon

Registered User.
Local time
Today, 03:14
Joined
Oct 25, 2001
Messages
65
Thanks for your response

So now I have:

DoCmd.SendObject acReport, "aReport", acFormatRTF, "a@b.c", , , "This is the subject", "This is the body of the email", False

How do I send multiple reports in this single email? Eg I want to send the reports "aReport", "aReport2" and "aReport3" all in the one email. How do I achieve this?

Also, the email still doesn't send automatically. It will put the message in the outbox, and wait for the next send/Receive to occur. That is ok, since I have it automatically sending/receiving every minute. However, if I do not have the email client open, this will not occur. Is there any way to get it to automatically open the email client so that it will send?

Thanks again,

Peter
 

Users who are viewing this thread

Top Bottom