473,386 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Leban's print to pdf question: send pdf via email attachment from access

beltex63
Does anyone know how to:

Send active info from an open form (report references fields from open form) to a pdf document (which would get the document name from form fields) that would in turn open Outlook and have the pdf as an attachment.

I already have the mdb setup to open reports as pdf's.

Best regards,
Brent
Nov 20 '07 #1
4 2159
MMcCarthy
14,534 Expert Mod 8TB
Does anyone know how to:

Send active info from an open form (report references fields from open form) to a pdf document (which would get the document name from form fields) that would in turn open Outlook and have the pdf as an attachment.

I already have the mdb setup to open reports as pdf's.

Best regards,
Brent
Sorry Brent but your question is confusing. Prehaps if you posted the code you are using to open the reports as pdfs it would help. Are you then trying to email these reports as attachments?
Nov 27 '07 #2
I am using the following code along with Lebans print to pdf code:

Expand|Select|Wrap|Line Numbers
  1. Private Function CurrentDBDir() As String
  2. 'Code courtesy of Terry Kreft & Ken Getz
  3.  
  4. Dim strDBPath As String, strDBFile As String
  5.  
  6.     strDBPath = CurrentDb.Name
  7.     strDBFile = Dir(strDBPath)
  8.     CurrentDBDir = Left$(strDBPath, Len(strDBPath) - Len(strDBFile))
  9.  
  10. End Function
  11.  
  12. Private Function GetUniqueFilename(Optional path As String = "", _
  13. Optional Prefix As String = "", _
  14. Optional UseExtension As String = "") _
  15. As String
  16.  
  17. ' originally Posted by Terry Kreft to: comp.Databases.ms -Access
  18. ' Subject:  Re: Creating Unique filename ??? (Dev code)
  19. ' Date: 01/15/2000
  20. ' Author: Terry Kreft <terry.kreft@mps.co.uk>
  21. ' SL Note: Input strings must be NULL terminated.
  22.  
  23. Dim wUnique As Long
  24. Dim lpTempFileName As String
  25. Dim lngRet As Long
  26.  
  27.   wUnique = 0
  28.   If path = "" Then path = CurDir
  29.   lpTempFileName = String(MaxPath, 0)
  30.   lngRet = GetTempFileName(path, Prefix, wUnique, lpTempFileName)
  31.  
  32.   lpTempFileName = Left(lpTempFileName, InStr(lpTempFileName, Chr(0)) - 1)
  33.   Call Kill(lpTempFileName)
  34.   If Len(UseExtension) > 0 Then
  35.     lpTempFileName = Left(lpTempFileName, Len(lpTempFileName) - 3) & UseExtension
  36.   End If
  37.   GetUniqueFilename = lpTempFileName
  38.  
  39. End Function
  40.  
  41. Public Function SendMail(strRecipients As String, strSubject As String, strBody As String, vAttachments As String) As String
  42.  
  43. 'Written by Tom Wickerath, May 7, 2006.
  44. 'Entry  (strRecipients) = Semicolon delimited string of recipients.
  45. '       (strSubject) = Required. Message subject.
  46. '       (strBody) = Optional. Body of the message.
  47. '       (vAttachments) = List of files to attach to e-mail (separated by commas)
  48.  
  49. Dim myObject As Object, myItem As Object
  50. Dim vCount As Long
  51. Dim vArray() As String
  52.  
  53.     On Error GoTo ProcError
  54.  
  55.     Set myObject = CreateObject("Outlook.Application")
  56.     Set myItem = myObject.CreateItem(0)
  57.  
  58.     vArray = Split(vAttachments, ",")                                   'fetch attached filenames into vArray
  59.  
  60.     With myItem
  61.         .Subject = strSubject                                           'enter Subject text
  62.         .To = strRecipients
  63.  
  64.         If Len(Trim(strBody)) > 0 Then                                  'enter message text
  65.             .Body = strBody
  66.         End If
  67.  
  68.         For vCount = 0 To UBound(vArray)                                'scan array
  69.             .Attachments.Add (vArray(vCount))                           'add attachments
  70.         Next
  71.  
  72.         .Display
  73. '        .Send                                                           'this option will do the same as .Display but NOT display e-Mail program
  74.     End With
  75.  
  76. ExitProc:
  77.     Set myItem = Nothing
  78.     Set myObject = Nothing
  79.     Exit Function
  80.  
  81. ProcError:
  82.     MsgBox "Error " & Err.Number & ": " & Err.Description, _
  83.                vbCritical, "Error in SendMail Function..."
  84.     SendMail = "A problem was encountered attempting to automate Outlook."
  85.     Resume ExitProc
  86.     Resume
  87.  
  88. End Function
  89.  
  90. Public Sub EMailAsPDF(vReport As String, vPDFName As String, vEMail As String, vSubject As String, vBody As String)
  91.  
  92. 'Send Access report as a .pdf file to one (or more) e-mail addresses
  93. 'Entry  (vReport) = Name of report
  94. '       (vPDFName) = Name used for PDF file excluding .pdf extension
  95. '       (vEMail) = E-Mail address
  96. '       (vSubject) = Subject string
  97. '       (vBody) = Body of E-Mail string
  98.  
  99. 'To send a report attached to an e-mail use code like this in your forms :-
  100. '
  101. '    EMailAsPDF "YourReportName", "Name of PDF file", "Recipients e-mail address", "Subject Line", "Main body of e-mail text"
  102. '
  103. 'To send the report to more than one recipient add other e-mail addresses separated by semi-colons. i.e. "Joe@aol.com;Fred@tiscali.co.uk"
  104.  
  105.  
  106. Dim vFolder As String, vDBPath As String, vDBFile As String
  107. Dim vDummy As Variant
  108.  
  109.     On Error GoTo ErrorCode
  110.  
  111.     vDBPath = CurrentDb.Name                                                'fetch name of db folder
  112.     vDBFile = Dir(vDBPath)                                                  'extract filename
  113.     vFolder = Left$(vDBPath, Len(vDBPath) - Len(vDBFile))                   'fetch db folder name
  114.     vDummy = ConvertReportToPDF(vReport, vFolder & vPDFName & ".pdf")       'save Report to temp file as .PDF file
  115.     vDummy = SendMail(vEMail, vSubject, vBody, vFolder & vPDFName & ".pdf") 'send e-mail (with .PDF file attached)
  116.     Kill vFolder & vPDFName & ".pdf"                                        'delete temp file
  117.     Exit Sub
  118.  
  119. ErrorCode:
  120.     If Err = 2501 Or Err = 2465 Then Exit Sub                               'if user cancels e-mail then abort
  121.     Beep
  122.     MsgBox "Error Code " & Err & ": " & Error                               'else show error
  123.  
  124. End Sub
  125.  
  126.  
  127. The code is used along with a command button with the following code:
  128.  
  129. event procedure: on click
  130.  
  131. Private Sub Open_BOL_Click()
  132. EMailAsPDF "BOL", "Customer", "info@katybuys.com", "IMO", "Test"
  133. End Sub
  134.  

Instead of using hard coded customer name, email address, etc., I would like to use fields from my form to fill in the customer name, email address, document name and subject.

Thanks,
Brent
Nov 27 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
Hi Brent

Will this work for you ?

SendMail(Me!EmailControl, Me!SubjectControl, Me!BodyControl, Me!DocumentPath)

Substitute each control name with the name of the control on your form.
Nov 27 '07 #4
I used the following and it worked:

EMailAsPDF "IMO 1", Me.Title & Me.Dash & Me.po1 & Me.po, "email address here", Me.Title & Me.Dash & Me.po1 & Me.po, Me.Assigned_To.Column(1)
Dec 1 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: MLH | last post by:
I want to send 2 reports using SendObject. Something like this would do nicely... DoCmd SendObject A_REPORT, "rpt1";"rpt2", A_FORMATRTF, MyRecip, , , MySubject, MyBodyText, 0 ....except for...
10
by: Ty Smith via AccessMonster.com | last post by:
I noticed that the week numbers in Stephan Leban's MonthCalendar are not consistent with Microsoft Outlook (they are shifted one week forward). Is there any way I can sync these two up by changing...
5
by: Sean | last post by:
Hi... I want to use the macro/sendobject (or any other procedure) to send the contents of a table (very small, ~5 rows/columns) as an Outlook message body, not as an attachment. Access 2000 will...
3
by: vtashore | last post by:
I downloaded Steve Leban's RTF2 control and it works as advertised. Good news! After reading reference material on the RTF standard codes, I have been able to write update queries to universally...
3
by: =?Utf-8?B?SHVnaA==?= | last post by:
Hi There, I use follow code to send email inside VB.NET 2005. It does not work well. Error message of "Failure sending email" would occue. However, email was sent out sometimes. I am confused...
2
by: Pascal Hagedorn | last post by:
I downloaded Steve Leban's RTF2 control and it shows me the report as wanted. The Problem is, if i want to print it, it comes a PopUp where it says "properties write protected" (german:...
9
by: Tom | last post by:
Hi all: I'm having an odd problem with Stephen Leban's PDF creator. I'm trying to output to 11x17 sized paper. The PDF creator does its thing and when the PDF file opens, its at 800% zoom and...
35
by: JessicaZ | last post by:
Hi everyone! I'm new here and have a question regarding Leban's report to pdf tool. I am working on a database where we are using this code to send a report out to pdf(duh) BUT what I need to do is...
1
by: deepaks85 | last post by:
Dear All, I want to send some data through a form with Multiple attachment in an HTML Format. I have tried it but it is not working for me. I am able to send data without attachment but with the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.