PDA

View Full Version : Solved: email a pdf from MS Access



DBinPhilly
02-08-2010, 10:05 AM
Is there a way to email a pdf report in an MS Access subroutine?

I know that I can use SendObject to send a Snapshot View of a report. But who is at the other end to read it? The CIA could use snapshot format to send secret documents and no one would be able to break the code.

I need to send things as pdf's.

Again, I need to send a pdf from a MS Access program directly to an email attachment.

Is this possible?

OBP
02-08-2010, 01:50 PM
Yes, it is possible

Dim objOutlook As New WinMail.Application ' outlook object
Dim objMessage As MailItem, strAttach As String ' outlook mail message
Dim Subject As String, Body As String, EmailAddress As String
EmailAddress = Me.EmailAddress
strAttach = Me.Attachment
Set objMessage = objOutlook.CreateItem(olMailItem)
With objMessage
.To = EmailAddress
.Subject = "Test Send"
.Body = "This is a Test"
.Attachments.Add strAttach
.Send
End With
Set objOutlook = Nothing
Set objMessage = Nothing


Where Me.EmailAddress is an email address on the form and so is the path to the attachment - Me.Attachment

DBinPhilly
02-09-2010, 08:38 AM
Thank you for your help.

your original code wouldn't work for me but I made a couple of minor modifications and it runs like a champ.

I just 'remarked out' the offending lines. here is what I came up with (leaving in your original lines rem'd out for clarity):


Dim objOutlook As Object
Dim objEmail As Object

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

' Dim objOutlook As New WinMail.Application ' outlook object
Dim objMessage As MailItem, strAttach As String ' outlook mail message
Dim Subject As String, Body As String, EmailAddress As String
EmailAddress = myEAddress
strAttach = myAttach
' Set objMessage = objOutlook.CreateItem(olMailItem)
' With objMessage
With objEmail
.To = EmailAddress
.Subject = mySubject
.Body = myBody
.Attachments.Add strAttach
.Send
End With
Set objOutlook = Nothing
Set objMessage = Nothing


Thanks for your help. It opens up a vast number of possiblities.

geekgirlau
02-14-2010, 07:40 PM
DB don't forget to use the VBA tags when posting code - highlight the code, then click on the green "VBA" button.

Imdabaum
03-16-2010, 11:23 AM
Can you use BCC in this code?

It doesn't seem to do work for me.

.....Nevermind...

Just had to compile the project.