Snowflake68
Registered User.
- Local time
- Today, 03:51
- Joined
- May 28, 2014
- Messages
- 464
I have found a thread on here with the code below which I am using (Thank you 'stopher') However I would like to add in something that checks to see if the email was closed without sending and then pop up a message just informing the user of this.
Ive tried adding in this code which I also found with some code for SendObject which works on the SendObject code but not on the 'With MailOutLook' code. It doesnt produce any errors but doesnt pop up the message when I close the email either. It just prompts so see if I want to save the email.
Can anyone advise me please?
Code:
Public Sub SendEmail()
Dim appOutLook As Object
Dim MailOutLook As Object
'create the two reports temporarily
DoCmd.OutputTo acOutputReport, "Report1", acFormatPDF, "c:\someLocation\Report1.pdf", False
DoCmd.OutputTo acOutputReport, "Report2", acFormatPDF, "c:\someLocation\Report2.pdf", False
'assign our object references
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
'set the recipient list
.To = "someone@somewhere.com"
'set the subject
.Subject = "My Reports"
'set the body text
.body = "Here are the reports in pdf format"
'add the reports we created
.attachments.Add "c:\someLocation\Report1.pdf"
.attachments.Add "c:\someLocation\Report2.pdf"
'send the email
.Send
End With
'tidy up..
'get rid of our object references
Set appOutLook = Nothing
Set MailOutLook = Nothing
'delete our temporary files
Kill "c:\someLocation\Report1.pdf"
Kill "c:\someLocation\Report2.pdf"
End Sub
Ive tried adding in this code which I also found with some code for SendObject which works on the SendObject code but not on the 'With MailOutLook' code. It doesnt produce any errors but doesnt pop up the message when I close the email either. It just prompts so see if I want to save the email.
Can anyone advise me please?
Code:
On Error GoTo cmdEmail_Click_Err
'code goes here
cmdEmail_Click_Exit:
Exit Sub
cmdEmail_Click_Err:
MsgBox "Email NOT sent for quote ", vbCritical, "Email Quote"
Resume cmdEmail_Click_Exit
Last edited: