Convert Report to PDF then Email

N

ncos

Hi Peole, im having some trouble getting my access database to email the pdf
thats being created. Ive managed to get the report automatically emailed as
a HTMl file but would really love to get the PDF conversion working and as
such have tried changing the "docmd.sendobject" I did for the HTMl
conversion, so far i've got the report to convert into a pdf (half way
through the code below) but the next line of code opens up an email with the
subject and email address correct but no pdf file attached, can anybody help
me?

Private Sub Command344_Click()
On Error GoTo Err_Command344_Click

Dim stDocName As String
Dim blRet As Boolean

stDocName = "WorkOrders"
DoCmd.OpenReport stDocName, acPreview, , "WorkOrderID = " & WorkOrderID



blRet = ConvertReportToPDF("WorkOrders", vbNullString, "Trust Orthotics
Invoice - " & [InvoiceNumber] & ".PDF", False)

DoCmd.SendObject , "Trust Orthotics Invoice - " & [InvoiceNumber] & ".PDF",
, To:=[emailaddy], _
Subject:="Trust Orthotics Invoice - " &
[InvoiceNumber], EditMessage:=True




DoCmd.Close acReport, "WorkOrders"

Exit_Command344_Click:
Exit Sub

Err_Command344_Click:
MsgBox Err.Description
Resume Exit_Command344_Click

End Sub
 
A

Albert D. Kallal

blRet = ConvertReportToPDF("WorkOrders", vbNullString, "Trust Orthotics
Invoice - " & [InvoiceNumber] & ".PDF", False)

Your output file name in the above is:

"Trust Orthotics Invoice - " & [InvoiceNumber] & ".PDF"

The above needs to be a legitimate FULL path name to your disk drive. The
above statement is creating a pdf file on your disk drive.

Do you have the above creating the pdf file on disk? I don't see any path
name for the above file name..and thus I have no idea were you are saving
the PDF file, or where you plan to save the PDF file.


Do you have the above working? The above code requites you to create a pdf
file, and save it to the disk drive. That what the above code does.

have you looked at the file on disk? (where is it being saved???).

You likely should create some folder, and specify some path name as to where
you going to save this pdf file.

Until you get the above working correctly, I don't think you should worry
about the email part.
DoCmd.SendObject

You can't use SendObject to attach a excel, publisher, jepg, wave or any old
file (including the above pdf file you just saved) from the disk drive.

you have to use automaton, and that generally means you have to use outlook,
and cannot use outlook express.

Get the 1st step working, and then your next question is

"how can specify any file from the disk drive as an email attachment" ?
 
N

ncos

Thanks Albert, getting closer now I've altered the PDF code slightly (see
below) so a PDF is now saved in the invoices folder and also altered the
code for docmd.sendobject but the PDF is not being attached to the email,
any ideas?

Many Thanks,
Neil



blRet = ConvertReportToPDF("WorkOrders", vbNullString, "c:\invoices\Trust
Orthotics Invoice - " & [InvoiceNumber] & ".PDF", False)

DoCmd.SendObject , "c:\invoices\Trust Orthotics Invoice - " &
[InvoiceNumber] & ".PDF", , To:=[emailaddy], _
Subject:="Trust Orthotics Invoice - " &
[InvoiceNumber], EditMessage:=True
 
A

Albert D. Kallal

Thanks Albert, getting closer now I've altered the PDF code slightly (see
below) so a PDF is now saved in the invoices folder and also altered the
code for docmd.sendobject but the PDF is not being attached to the email,
any ideas?

Many Thanks,
Neil

Yes, I will re-quote from my last post:

<quote>

You can't use SendObject to attach a excel, publisher, jepg, wave or any old
file (including the above pdf file you just saved) from the disk drive.

You have to use automaton, and that generally means you have to use outlook,
and cannot use outlook express.
</quote>

So, can't use SendOjbect. SendObject DOES NOT allow you to attach a file
from the disk drive to a email. I not sure how I can be any more clear in my
english here.

Again:

SendObject DOES NOT ALLOW you to attach a fiel from the disk drive to a
email.

You have to use outlook automaton (it means the user MUST have outlook, and
can NOT use outlook express).

Here is an example:

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


DoCmd.OpenReport strReportName, acViewPreview, , strWhere, , strOpenArgs
Reports(strReportName).Visible = False
Call ConvertReportToPDF(strReportName, , strDocName, False, False)
DoCmd.Close acReport, strReportName

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
.Attachments.Add (strDocName)
.Display
' .Send
End With


Exit Sub


CreateOutLookApp:

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


The above is a rought outline. You can actually attached MORE then one file
to the email...

So, you have to use automaton, and CAN NOT use SendObject....
 
R

Roland Malo

Hi nice people
Many thanks Albert, your conversation with Neil on 12&13 Nov. about conversion Access report to PDF and mailed automatically was very helpful to me.
1 – the line Call ConvertReportToPdf (Str……) doesn’t work, return: function not defined, same for GetNameSpace
2 - I am fronting the same problem but on sending the report as a body of the email using outlook. Can’I put my PDF document in line
..Body = StrDocName

Any help

Roland


EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 

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