E-Mail Multiple Reports? See Code Below, is this possible?

D

Dave Elliott

On Error GoTo Error_Handler



Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

I have a continous form that shows my Customer, Invoice Number, Bid Price
and Job Description (frminvlist)
I also have a Yes/No control on the form named Selected, Default is No
These are all from the same table.
If I check the Yes/No control and then choose the Command Button on the form
named Command203,
Then I wish to open all the Invoices,Hidden and then send to my
CutePDFPrinter, I have been doing this by a macro
SelectObject Report RMothStatmnt
RunCommand Print
And then saving the reporrtt as a file, then clicking on the command button
on my main form to e-mail
This works ok for just one Invoice.
The code below is for the Command203 button on the form.
Is there a way to send all the Invoices I check to the printer,create a pdf
and then e-mail all of the selected invoices?


With objEmail
.To = InputBox("Type Address Here!")
.Subject = "Invoice from Gulf Coast Electric"
.body = "Thanks for your Business"
.Attachments.Add "C:\PDFReports\Invoice.pdf"
'.attachments.Add "c:\Path\to\the\next\file.txt"
.Send
'.ReadReceiptRequested
End With

Exit_Here:
Set objOutlook = Nothing
Exit Sub

Error_Handler:
MsgBox err & ": " & err.Description
Resume Exit_Here
 
T

Todd Shillam

Yes--it is possible. I have a form with a button that output's several reports to a folder on a network file server.

Then I have several modules that are 'called' to send e-mail with attachments to several recipients. Here's an example module, called modSendMessageA:

========= START HERE =========

Option Compare Database
Option Explicit

Sub SendMessageA(Optional AttachmentPath)

'DECLARING OUTLOOK VARIABLES
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

'DECLARING LOCAL VARIABLES
Dim vDate As String
Dim strFile As String
Dim strFileName As String

'INITIALIZING LOCAL VARIABLES
strFileName = "-OutputTest.RTF" '<<<< CHANGE FILE NAME HERE
vDate = Format(Now, "mmm yyyy")
strFile = vDate & strFileName 'JOINS DATE AND FILE DESCRIPTION TO MAKE FILE NAME

'CREATES OUTLOOK SESSION
Set objOutlook = CreateObject("Outlook.Application")

'CREATES OUTLOOK MESSAGE
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
'ADD THE RECIPIENT(S) TO THE MESSSAGE
Set objOutlookRecip = .Recipients.Add("Todd Shillam") '<<<< EDIT NAME HERE
objOutlookRecip.Type = olTo

'======================================
'DISABLED CODE
'======================================
'ADD THE CC RECIPIENT(S) TO THE MESSAGE
'Set objOutlookRecip = .Recipients.Add("") '<<<< EDIT HERE
'objOutlookRecip.Type = olCC
'======================================


'SET THE SUBJECT, BODY, AND IMPORTANT OF THE MESSAGE
.Subject = "TYPE YOUR SUBJECT HERE"
.Body = "TYPE BODY OF MESSAGE HERE." & vbCrLf & vbCrLf 'THE vbCrLf CREATES A NEW LINE
.Importance = olImportanceHigh '<<<< CHANGE IMPORTANCE LEVEL HERE

'ADD ATTACHMENTS TO MESSAGE HERE
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath + strFile) 'ADD ADDITIONAL ATTACHMENTS BY ADDING NEW LINE
End If

'RESOLVE EACH RECIPIENT'S NAME
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next

'.Send 'DISABLED


End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub


========= END HERE =========



On the button's OnClick event, I call the various modules:

modSendMessageA
modSendMessageB
modSendMessageC
etc.

I don't have my script on-hand for the event; however, I'll try to get it tomorrow and post it.

Good luck,

Todd
On Error GoTo Error_Handler



Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

I have a continous form that shows my Customer, Invoice Number, Bid Price
and Job Description (frminvlist)
I also have a Yes/No control on the form named Selected, Default is No
These are all from the same table.
If I check the Yes/No control and then choose the Command Button on the form
named Command203,
Then I wish to open all the Invoices,Hidden and then send to my
CutePDFPrinter, I have been doing this by a macro
SelectObject Report RMothStatmnt
RunCommand Print
And then saving the reporrtt as a file, then clicking on the command button
on my main form to e-mail
This works ok for just one Invoice.
The code below is for the Command203 button on the form.
Is there a way to send all the Invoices I check to the printer,create a pdf
and then e-mail all of the selected invoices?


With objEmail
.To = InputBox("Type Address Here!")
.Subject = "Invoice from Gulf Coast Electric"
.body = "Thanks for your Business"
.Attachments.Add "C:\PDFReports\Invoice.pdf"
'.attachments.Add "c:\Path\to\the\next\file.txt"
.Send
'.ReadReceiptRequested
End With

Exit_Here:
Set objOutlook = Nothing
Exit Sub

Error_Handler:
MsgBox err & ": " & err.Description
Resume Exit_Here
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top