By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,456 Members | 1,251 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,456 IT Pros & Developers. It's quick & easy.

Multiple Reports attached to an email

100+
P: 135
So, I have a database I'm using for Employee Time Sheets. The pay period is a two week cycle. There is one report for each week. I would like to just combine the two weeks into one report, but my company has this "interesting" (say backwards) system that they don't want to change. So instead of filling out the time sheets by hand *gasp* (I know) I created a database (obviously). Anyway, how can I attach both reports to a single email? I have a button for emailing that will send both reports to my email, but each report creates its own message and attaches itself. Don't really want to send two emails for each employee. Thanks for your always mind blowing help.
Nov 16 '08 #1
Share this Question
Share on Google+
5 Replies


100+
P: 135
Sorry. I am using office 2007. So outlook is my email app. Thanks
Nov 16 '08 #2

100+
P: 135
Just moving the thread back to the top hoping for an answer.
Nov 16 '08 #3

nico5038
Expert 2.5K+
P: 3,072
For this you'll need to save the reports as a file and create an email with multiple attachments.

I assume you can create the needed files, here (part of) the Microsoft sample code for creating outlook emails with attachments.
Expand|Select|Wrap|Line Numbers
  1. Sub CallCreateMail()
  2.     ' This procedure shows how to pass an array of recipients,
  3.     ' a subject line, a message body, and an array of attachments
  4.     ' to the CreateMail procedure.
  5.     Dim strSubject      As String
  6.     Dim strBody         As String
  7.     Dim avarRecip(2)    As Variant
  8.     Dim avarAttach(2)   As Variant
  9.  
  10.     ' Create recipients array.
  11.     avarRecip(0) = "Maria Anders"
  12.     avarRecip(1) = "Ana Trujillo"
  13.     avarRecip(2) = "Antonio Moreno"
  14.  
  15.     ' Create attachments array.
  16.     avarAttach(0) = "c:\bootlog.txt"
  17.     avarAttach(1) = "c:\autoexec.bat"
  18.     avarAttach(2) = "c:\config.sys"
  19.  
  20.     ' Create Subject line and message body.
  21.     strSubject = "This is the subject line."
  22.     strBody = "If not now, when? If not you, who?"
  23.  
  24.     If CreateMail(avarRecip, strSubject, strBody, avarAttach) = True Then
  25.         MsgBox "Congratulations! Your mail has been sent."
  26.     End If
  27.  
  28. Function CreateMail(astrRecip As Variant, _
  29.                     strSubject As String, _
  30.                     strMessage As String, _
  31.                     Optional astrAttachments As Variant) As Boolean
  32.     ' This procedure illustrates how to create a new mail message
  33.     ' and use the information passed as arguments to set message
  34.     ' properties for the subject, text (Body property), attachments,
  35.     ' and recipients.
  36.  
  37.     Dim objNewMail          As Outlook.MailItem
  38.     Dim varRecip            As Variant
  39.     Dim varAttach           As Variant
  40.     Dim blnResolveSuccess   As Boolean
  41.  
  42.     On Error GoTo CreateMail_Err
  43.  
  44.     ' Use the InitializeOutlook procedure to initialize global
  45.     ' Application and NameSpace object variables, if necessary.
  46.     If golApp Is Nothing Then
  47.         If InitializeOutlook = False Then
  48.             MsgBox "Unable to initialize Outlook Application " _
  49.                 & "or NameSpace object variables!"
  50.             Exit Function
  51.         End If
  52.     End If
  53.  
  54.     Set golApp = New Outlook.Application
  55.     Set objNewMail = golApp.CreateItem(olMailItem)
  56.     With objNewMail
  57.         For Each varRecip In astrRecip
  58.             .Recipients.Add varRecip
  59.         Next varRecip
  60.         blnResolveSuccess = .Recipients.ResolveAll
  61.         For Each varAttach In astrAttachments
  62.             .Attachments.Add varAttach
  63.         Next varAttach
  64.         .Subject = strSubject
  65.         .Body = strMessage
  66.         If blnResolveSuccess Then
  67.             .Send
  68.         Else
  69.             MsgBox "Unable to resolve all recipients. Please check " _
  70.                 & "the names."
  71.             .Display
  72.         End If
  73.     End With
  74.  
  75.     CreateMail = True
  76.  
  77. CreateMail_End:
  78.     Exit Function
  79. CreateMail_Err:
  80.     CreateMail = False
  81.     Resume CreateMail_End
  82. End Function
  83.  
More code can be found at the Microsoft site.

Nic;o)
Nov 16 '08 #4

100+
P: 135
Thanks Nico,
I guess I was just hoping there might be some easier way before I dive into manipulating Outlook (I have yet to sail those waters). But...I guess not. Thanks again.
Nov 16 '08 #5

nico5038
Expert 2.5K+
P: 3,072
Hmm, you might try to create one report with both weekly reports as sub reports, but that will probably give some page layout problems. The combined report can be mailed "straight away"

Nic;o)
Nov 16 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.