Microsoft
Software
Hardware
Network
Question : email a .pdf
II have a data entry form . After a person enters data they need to view an Access report of that data to see that it is correct. After they review the report, then the report needs to be emailed to Headquarters.
I want to a button on the form that says, "Save and Email". I would like the code to:
1. Save the report as a .pdf
2. Email it from Outlook (I have some of the code for that and will use the Outlook board for help)
Questions:
1. Is there another option other than a .pdf? I am not sure the client as Adobe Writer.
2. Have any of you done something similar? What were the results?
Thanks. Sasha
Answer : email a .pdf
Here's a routine I developed that does what you are asking. It utilizes the PDF995 pdf writer (inexpensive). A benefit is that the PDF995 writer is can be configured to direct output to a new mail message with the PDF file already attached (that's how it is implemented here). I created a toolbar button to call the function. The toolbar button is displayed on all report Print Preview screens.
Public Function CopyObject2()
On Error GoTo Err_CopyObject2
'this function determines the type and name of the current active
'database object, creates a copy named based upon the system number
'retrieved, assigns the PrtDevNames & PrtDevMode properties based
'upon a blank report template (set to print to the PDF writer) and
'then prints the report. The new database object is deleted after
'the OutputToPDF function concludes.
Dim intCurrentType As Integer, intState As Integer
Dim strQuote As String, varSale As Variant
Dim strCurrentName As String, strJobNumber As String
Dim strMsg As String, strErrMsg As String, strObjMsg As String
Dim intSuccess As Integer
Dim rptNew As Report, rptTemplate As Report
strMsg = "Cannot copy database object - No job number specified"
strErrMsg = "Error copying/deleting database object. Please contact"
strErrMsg = strErrMsg & vbNewLine & "your administrator."
strObjMsg = "Only reports can be output to PDF format"
'get current db object type & name
intCurrentType = Application.CurrentObjectT
ype
strCurrentName = Application.CurrentObjectN
ame
'make sure the current object is a report (3)
If intCurrentType <> 3 Then
MsgBox strObjMsg, vbOKOnly, "Not Allowed"
GoTo Exit_CopyObject2
End If
'''''''''' I've eliminated a portion that obtained the current quote/invoice number for use in naming the PDF output
'''''''''' this remaining piece of code uses the current report name and appends and underscore
'if no system number, use current report name appended with "_"
If strJobNumber = "" Then
strJobNumber = strCurrentName & "_"
End If
'create copy of current object naming it with the system number
DoCmd.CopyObject , strJobNumber, intCurrentType, strCurrentName
'assign the system number to public variable
ObjectName = strJobNumber
PrintPDF: 'Set PrtDevNames, PrtDevMode properties and print object
'close current report
DoCmd.Close acReport, strCurrentName
'open new report & template report in design mode so
'properties can be manipulated
DoCmd.OpenReport ObjectName, acViewDesign
DoCmd.OpenReport "rptPDFPrinterTemplate", acViewDesign
Set rptNew = Reports(ObjectName)
Set rptTemplate = Reports("rptPDFPrinterTemp
late")
'assign PrtDevNames & PrtDevMode property for new report
rptNew.PrtDevNames = rptTemplate.PrtDevNames
rptNew.PrtDevMode = rptTemplate.PrtDevMode
'close reports
DoCmd.Close acReport, ObjectName, acSaveYes
DoCmd.Close acReport, "rptPDFPrinterTemplate", acSaveNo
'Print new report
DoCmd.OpenReport ObjectName, acViewNormal
'delete object only if it was created above
If ObjectName <> strCurrentName Then
DoCmd.DeleteObject intCurrentType, ObjectName
End If
'reopen current object
DoCmd.OpenReport strCurrentName, acViewPreview
'Debug.Print intCurrentType
'Debug.Print strCurrentName
'Debug.Print strJobNumber
Exit_CopyObject2:
Set rptNew = Nothing
Set rptTemplate = Nothing
Exit Function
Err_CopyObject2:
MsgBox strErrMsg, vbOKOnly, "Output Error"
Resume Exit_CopyObject2
End Function
To use this function PDF995 needs to be installed on the computer (it's free but displays banners; purchasing license eliminates banners). It will show up as a new printer. You'll need to confirue PDF995 to launch a new e-mail with the PDF attached as opposed to displaying a Save As dialogue box. Read the FAQ on software995's site for more info. You'll also need to create a blank report as the template (named rptPDFPrinterTemplate). Set this reports printer to the PDF995 printer and then save it.
When the user clicks the toolbar button Access will create a copy of the current report (with the underscore appended to the name), print the report to the PDF995 writer, and then delete the newly created report leaving the original intact. The PDF995 writer will output the newly created PDF file as an attachment to a new e-mail message using the default e-mail client on the machine (no need to automate Outlook).
Give it a shot and see what you think.
OM Gang
Random Solutions
Disable 'create profile' enquiry in Windows 7
Display No Rows or No Data Found Message for the Matrix in SSRS
Adding a unique identifier to a field for export
MS Word conversion to Adobe
Regional settings GREEK , decimal separator "," sql server 2000, But does not update a textbox tha binds to a float field,C# framework 2.0
SoapException when passing a class to web service
Can Access 2003 and 2007 coexist in peace on the same machine?
After OCS F-E's IP was changed, Services would't start - SQL connection lost?
Small Business Server 2008 - TASK Scheduler Errors
Access Query Error: specified expression as part of an aggregate function