?
Solved

email PDF from currently open form

Posted on 2014-04-22
10
Medium Priority
?
535 Views
Last Modified: 2014-04-27
I need to output the currently open Access form to a pdf and attach it to an email.

The code below will create a pdf from a named report and attach it to an email:
DoCmd.SendObject acSendReport, [name of report], acFormatPDF, "recipient@company.com",[cc email(s)],[bcc email(s)], [Message Subject], [MessageBody], True

Is it possible to print the currently open access form to a pdf attachment in an email?

Thank you in advance for your help.
0
Comment
Question by:Rwardlow
  • 5
  • 3
  • 2
10 Comments
 
LVL 40

Assisted Solution

by:PatHartman
PatHartman earned 500 total points
ID: 40014891
Reports are not optimized for printing.  In addition to subforms not working to expand to show all records, the backgrounds are too dark and so waste ink.  Create another report.

In order to control the records selected for a report exported as PDF, you need to use parameters in the query.  There is no "where" argument for the SendObject method as there is for the OpenForm and OpenReport methods.
0
 
LVL 1

Author Comment

by:Rwardlow
ID: 40015907
Thank you for your comment Pat, I am aware of the reasons it is not normal to print from forms. In this case we don't have the problems you reference. The forms print fine. However, I inherited this design with a lot of forms and the client would like to email pdf's. I have used VBA to manage PDF's with reports. I was curious if anyone had experience creating and emailing the currently open form.

Thanks again.
0
 
LVL 40

Expert Comment

by:PatHartman
ID: 40016005
You can use the OutputTo to print a form BUT it does NOT offer a where argument so it will print everything.  The ONLY way this will work, as I mentioned earlier,  is if you have used selection criteria in your form to select only the record you are viewing.  I don't believe filters will work.  Every record in the Form's RecordSource will end up in the pdf.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:Rwardlow
ID: 40016053
Thank you Pat. I understood. The forms in question only have 1 record in the RecordSource.
0
 
LVL 31

Accepted Solution

by:
Helen Feddema earned 500 total points
ID: 40018072
Here is some code to create a PDF from a report and email it.  As others have said, it is much better to use a report for this purpose.  Also, Automation code gives you a lot more control than the old SendObject method.

Public Sub ExportReportToPDF()
'Created by Helen Feddema 12-Jul-2013
'Last modified by Helen Feddema 12-Jul-2013

On Error GoTo ErrorHandler

   Dim appOutlook As New Outlook.Application
   Dim strReport As String
   Dim strSavePath As String
   Dim strReportFile As String
   Dim itm As Outlook.MailItem
   Dim strEmail As String
   
   strReport = "rptCurrentData"
   strSavePath = "G:\Documents\PDFs\"
   strEmail = "hfeddema@hvc.rr.com"
   strReportFile = strSavePath & "Current Data.pdf"
   
   'Create PDF file
   DoCmd.OutputTo objecttype:=acOutputReport, _
      objectname:=strReport, _
      outputformat:=acFormatPDF, _
      outputfile:=strReportFile, _
      autostart:=True
   
   'Create email
   strEmail = "Email address"
   Set itm = appOutlook.CreateItem(olMailItem)
   itm.Subject = "Message Subject"
   itm.Body = "Message body"
   itm.To = strEmail
   itm.Attachments.Add Source:=strReportFile, _
      Type:=olByValue
   itm.Display
   
ErrorHandlerExit:
   Set appOutlook = Nothing
   Exit Sub

ErrorHandler:
   MsgBox "Error No: " & Err.Number & "; Description: "
   Resume ErrorHandlerExit

End Sub

Open in new window

0
 
LVL 1

Author Comment

by:Rwardlow
ID: 40022316
Thank you for this example Helen. However, I am aware of all of the reasons why it is better to use a report for this purpose. I asked this question to see if someone knew how to create a pdf from a form. I have specific reasons. Apparently it is not possible.

Thank you very much for your help.
0
 
LVL 1

Author Closing Comment

by:Rwardlow
ID: 40022320
I assume this is not possible since no one answered my question.

Thank you
0
 
LVL 40

Expert Comment

by:PatHartman
ID: 40022550
You can "print" to a PDF printer or use OutputTo.  But OutputTo ONLY works if the recordset of the form is controlled by criteria in its RecordSource.  Filters will not work.
0
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 40022572
I tried exporting a form to PDF (there is such an option) in the interface, and while there were no error messages, the PDF was entirely blank.  If I have some time later on, I will experiment with creating a PDF from a form in code, just to see if it is possible.
0
 
LVL 1

Author Comment

by:Rwardlow
ID: 40025677
Thank you Helen, I appreciate your help. I have started using the print dialog in Acrobat manually. It would have been nice to be able to automate the whole process like you can with reports but that doesn't seem to be possible.
Thanks again.
Bob
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question