Email Report as Attachment with Voting Buttons

L

LDMueller

I have Access 2003 and Outlook 2003. I want to email a report to someone as
an attachment, but I also want the email to have voting buttons. I was able
to write the code with help from other snipets I found.

I have everything working except as coded below, I can attach a file, but I
can't attach the report named "rptAnnualRpt".

Note I can attach a report using DoCmd.SendObject, but then I don't know how
to add the voting buttons.

Here's my code...
Sub sbSendMessage(Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objoutlook1 As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add("John Doe")
objOutlookRecip.Type = olTo
Set objOutlookRecip = .Recipients.Add("Jane Doe")
objOutlookRecip.Type = olCC
.Subject = "Annual Report"
.Body = "Attached is your report."
.VotingOptions = "Yes, Report is Accurate;No, Report is Inaccurate"

' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing
ErrorMsgs:
MsgBox Err.Number, Err.Description
End Sub

Private Sub cmdSend_Click()
Me.sbSendMessage ("C:\Documents and Settings\ldm\My
Documents\Customers.txt")
End Sub

Thanks in advance!

LDMueller
 
L

LDMueller

Thank you for your reply. While I didn't use your exact suggestion, it was
your suggestion which helped me resolve my issue.

Basically I saved the report first and used my code to send it as the
attachment.

Thanks again!
LDMueller
 
M

Mark Andrews

Glad you got it working, I thought that was my exact suggestion:
Why don't you just:
1. use code to run a report and save it as a PDF file (or other file format
you like)
2. run your outlook code using the file created in step 1 asa the attachment
3. delete the file created in step 1 (or cleanup at the end, your choice)
repeat process for all emails that need to go out.

Anyway yea!
Mark
 

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