Sending reports as attachments through Outlook 
Author Message
 Sending reports as attachments through Outlook

I pulled the following code off the MS site and wonder if I can get some
help (the purpose is to use automation to send some Access reports through
Outlook).  I have three specific questions: (1) how can I get the recipitent
line to roll through the record set on which the report is based: is there
some SQL/VBA I can use [I would like to attach one record-specific page to a
message, have it sent, then attach another page and so on]? I thought of
setting up an array or a loop . . . .   (2)  What's the AttachmentPath
referred to in section under .Body?  (3) Has anyone tried this and will it
work or is there abetter way?

Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
          Dim objOutlook As Outlook.Application
          Dim objOutlookMsg As Outlook.MailItem
          Dim objOutlookRecip As Outlook.Recipient
          Dim objOutlookAttach As Outlook.Attachment

          ' Create the Outlook session.
          Set objOutlook = CreateObject("Outlook.Application")

          ' Create the message.
          Set objOutlookMsg  = objOutlook.CreateItem(olMailItem)

          With objOutlookMsg
              ' Add the To recipient(s) to the message.
              Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
              objOutlookRecip.Type = olTo

              ' Set the Subject, Body, and Importance of the message.
             .Subject = "Dining Room Invoice"
             .Body = "You will find attached your most recent invoice for
meals taken in the Dining Room as of the date indicated. " &vbCrLf &vbCrLf
&"Please remit payment with a copy of the invoice  to the following address
as soon as possible:" &vbCrLf &vbCrLf &"Michael Ratzlaff" &vbCrLf &vbCrLf

            ' Add attachments to the message.
             If Not IsMissing(AttachmentPath) Then
                 Set objOutlookAttach = .Attachments.Add(AttachmentPath)
             End If

             ' Resolve each Recipient's name.
             For Each ObjOutlookRecip In .Recipients
                 objOutlookRecip.Resolve
             Next

             ' Should we display the message before sending?
             If DisplayMsg Then
                 .Display
             Else
                 .Save
                 .Send
             End If
          End With
          Set objOutlook = Nothing
      End Sub



Sun, 19 Oct 2003 21:07:54 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Send SMTP mail (with attachments), without using Outlook

2. Outlook Express - Sending mail with attachments

3. macro for outlook to send multiple mail with multiple attachments

4. Help useing a variable to send attachments with outlook

5. Using MAPI and Outlook to send email attachments?

6. use VBA send a snapshot type report out as an attachment of an email

7. Send report as e-mail(attachment) Access97

8. send report as an attachment in Visual Basic 6

9. How send by mail report with ocx with pdf attachment

10. How send a report in CR 8.5 /VB 6 with PDF attachment

11. how i send attachment in the biginnig when sending the mail with olemsg32.dll

12. Accept drops of messages from Outlook and Dragging attachments from MS Outlook

 

 
Powered by phpBB® Forum Software