SendObject with PDF

K

katz

Van T. Dinh, responded to my question, about creating PDF from Access
(thanks for your quick response)

Hello, Lebens has a nice tool to create PDF from Access report.
Is there a way to combine the PDF report with SendObject?
With Sendobject I can send a report and take the email adrs from the
customer
file. By pressing a button it will attach the report with the email adrs and
ready to send. The user only has to press the send button.
The only problem is that Sendobject doesn't support PDF format.
Thanks
Abe
 
A

Albert D. Kallal

Actually, your question would not be restricted to a PDF file. It could a
picture, a movie file, or a excel sheet.

You are talking about some windows file sitting on the disk drive. In your
case it is a pdf file that you just created, but really, it could be any old
PDF file.

So, your question is actually:

how can I attach a windows file of my choice to a email?

Well, if you use outlook, then you can very well easy do this. If you using
something lese (like outlook express), then it becomes more difficult.


for outlook, you can use:


' send to user via email
' gen the doc to send
Dim myreport As Report
Dim picturecount As Long

'Dim ol As Outlook.Application
Dim ol As Object ' Late binding 10/03/2001 -
Ak
'Dim ns As NameSpace
Dim ns As Object ' Late bind

'Dim newmessage As MailItem
Dim newmessage As Object ' Late bind

Dim mymessage As String

'Dim objOutlookAttach As Outlook.Attachment
'Dim objOutlookAttach As Object

'Kill strDocName

DoCmd.OpenReport strReportName, acViewPreview, , strWhere, , strOpenArgs
Reports(strReportName).Visible = False

'DoCmd.OutputTo acReport, strReportName, acFormatRTF, strDocName, False
Call ConvertReportToPDF(strReportName, , strDocName, False, False)

DoCmd.Close acReport, strReportName

' created the pdf report.....now start the email...


Dim MySql As String

On Error GoTo CreateOutLookApp
Set ol = GetObject(, "Outlook.Application")
On Error Resume Next

Set ns = ol.GetNamespace("MAPI")
ns.Logon

Set newmessage = ol.CreateItem(0) ' 0 = olMainItem
With newmessage
.Recipients.Add strEmailTo
.Subject = strSubject
.Body = strMsgText

'Set objOutlookAttach = .Attachments.Add(stDocName)
.Attachments.Add (strDocName)

.Display

' .Send

End With

Exit Sub


CreateOutLookApp:

Set ol = CreateObject("Outlook.application")
Resume Next
 
S

Stephen Lebans

Albert would you mind if I copy and paste your reply in this thread to the
ReportToPDF Web page?

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
A

Albert D. Kallal

Albert would you mind if I copy and paste your reply in this thread to the
ReportToPDF Web page?

Sure, please do, but I would have cleaned it up a bit more if I knew that!
;-)

In fact, here is the full code listing.

Note that the first code snip is designed to be placed on a custom menu bar
(one that I use for ALL reports). The custom menu bar simply has a email as
pdf button on it. So, while looking at ANY report, you simply "click" on
the email button...

All that is needed is to place the name of the function in custom menu bars
on-action setting

eg:

=AskReportSend()

So, the code to "call" the pdf code from the reprot menu is:

Public Function AskReportSend()

' this is the email option included on every report

Dim rptActiveReport As Report
Dim strEmail As String
Dim strSubject As String
Dim strBodyText As String
Dim strDocName As String

strSubject = ""
strBodyText = ""

Set rptActiveReport = Screen.ActiveReport

strEmail = ""

strDocName = CurrentProject.path & "\" & rptActiveReport.Name & ".pdf"

Call EmailReport(rptActiveReport.Name, "For your information", "",
strDocName, "")


End Function

So, the above is used for all reports.

the code you just asked for follows:


Public Sub EmailReport(strReportName As String, _
strSubject As String, _
strMsgText As String, _
strDocName As String, _
strEmailTo As String)


' sends the active report out....
' send to user via email

Dim myreport As Report
Dim picturecount As Long

'Dim ol As Outlook.Application
Dim ol As Object ' Late binding 10/03/2001 - Ak
'Dim ns As NameSpace
Dim ns As Object ' Late bind

'Dim newmessage As MailItem
Dim newmessage As Object ' Late bind

Dim mymessage As String

'Dim objOutlookAttach As Outlook.Attachment
'Dim objOutlookAttach As Object

'Kill strDocName

MyPbar.ShowProgress
MyPbar.TextMsg = "Creating Report File"
MyPbar.Pmax = 4

' DoCmd.OpenReport strReportName, acViewPreview, , strWhere
' Reports(strReportName).Visible = False

'DoCmd.OutputTo acReport, strReportName, acFormatRTF, strDocName, False

Call ConvertReportToPDF(strReportName, , strDocName, False, False)

DoCmd.Close acReport, strReportName

' gene the doc...now start the email...


Dim MySql As String

On Error GoTo CreateOutLookApp
Set ol = GetObject(, "Outlook.Application")
On Error Resume Next

Set ns = ol.GetNamespace("MAPI")
ns.Logon

Set newmessage = ol.CreateItem(0) ' 0 = olMainItem
With newmessage
.Recipients.Add strEmailTo
.Subject = strSubject
.Body = strMsgText

'Set objOutlookAttach = .Attachments.Add(stDocName)
.Attachments.Add (strDocName)

MyPbar.IncOne

MyPbar.HideProgress
Set MyPbar = Nothing

.Display

' .Send


End With

MyPbar.HideProgress
Set MyPbar = Nothing

Exit Sub


CreateOutLookApp:

Set ol = CreateObject("Outlook.application")
Resume Next


End Sub

So, that about routine does not necessary need be called from a custom menu
(that is the job of the first code snip).

The only other tip I can offer is that a user can (and should) simply open
the report BEFORE calling the above routine if they want a particular
"where" clause, since your code will operate on the already opened (and more
importantly *filtered* report) if need be.
 

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