Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access report to PDF file to Email

Status
Not open for further replies.

LonnieJohnson

Programmer
Apr 16, 2001
2,628
0
0
US
Is there a process by which an Access report can be saved to a pdf file then attached to an email without any manaul intervention or use of additional dll files?

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Lonnie
Could you, from a form, have a command button that Prints the report in PDF, and then have a second line in the code that sends the object (one DoCmd line to print, followed by a DoCmd.SendObject line)?

Tom
 
I don't think the send object has an option for pdf files as the output format.

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Maybe save the report as pdf using whatever method - Adobe Distiller, Pdf995, then send the resulting file through CDO?

For some (unknown) reason, on some machines late binding does not work, even though CDOEX.dll is registered properly. In such cases, set a reference to it and use early binding.

Below is a piece of code I found some long time ago on Microsoft's site.

Code:
Option Compare Database
Option Explicit
Const cdoSendUsingPort = 2

Function CDOSend(ServerName As String, _
UserName As String, _
Password As String, _
ToRecipients As String, _
CCRecipients As String, _
BCCRecipients As String, _
Subject As String, _
Body As String, _
ParamArray Attachments() As Variant) As String

'ServerName: name or IP of the email server
'UserName: a valid email account
'Password: everone knows what that is
'ToRecipients: list of recipients, 'To' field
'CCRecipients: list of recipients, 'CC' field
'BCCRecipients: list of recipients, 'BCC' field
'Subject: whatever mail subject
'Body: some meaningless text
'Attachments: list of files to be attached, separated by comma

Const conRetries = 10

Dim intRetries As Integer
Dim strServer As String
Dim strUserName As String
Dim strPassword As String

Dim strFileName
Dim i As Integer
 

'========================================================
'====Uncomment the block if late binding does not work===
'========================================================
 'Dim IMSG As New CDO.Message
 'Dim ICONF As New CDO.Configuration
 '=======================================================


'========================================================
'====Comment the block if late binding does not work=====
'========================================================
 Dim IMSG As Object
 Dim ICONF As Object
'======================================================== 
 

 strServer = ServerName
 strUserName = UserName
 strPassword = Password
 
 
start:

 
 On Error GoTo errhandler
   
   Set IMSG = CreateObject("CDO.Message")
  Set ICONF = CreateObject("CDO.Configuration")
 
 
    With ICONF.Fields
  
' configuration information for SMTP server
' Specifie the method used to send messages.
.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = _
cdoSendUsingPort

' The name (DNS) or IP address of the machine
' hosting the SMTP service through which
' messages are to be sent.
.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = _
strServer ' Or "mail.server.com"

' Specify the authentication mechanism
' to use.
.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")[/URL] = _
1

' The username for authenticating to an SMTP server using basic (clear-text) authentication
.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusername")[/URL] = _
strUserName

' The password used to authenticate
' to an SMTP server using authentication
.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendpassword")[/URL] = _
strPassword

' The port on which the SMTP service
' specified by the smtpserver field is
' listening for connections (typically 25)
.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = _
25

'Use SSL for the connection (False or True)
.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpusessl")[/URL] = _
False

' Set the number of seconds to wait for a valid socket to be established with the SMTP service before timing out.
.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")[/URL] = _
60

' Update configuration
.Update
  
  End With
 
 
 
 
 
 
 
   ' Build HTML for message body.
  
  
 
   ' Apply the settings to the message.
  With IMSG
      Set .Configuration = ICONF
      .To = ToRecipients  'Enter a valid email address.
      .cc = CCRecipients
      .bcc = BCCRecipients
      .FROM = UserName & "@yourdomain.com" 'Enter a valid email address.
      .Subject = Subject

      '.Body = "<html><body><b>Hello World</b></body></html>"

      .TextBody = Body
       
       'strfilename = Dir(AttachFolder & "\*.*", vbNormal)
For i = 0 To UBound(Attachments)

    On Error Resume Next
   .AddAttachment Attachments(i)
Next
On Error GoTo errhandler
       
      .Send
  End With
exithere:
 Set IMSG = Nothing
 Set ICONF = Nothing
Exit Function
errhandler:
If intRetries < conRetries Then
     intRetries = intRetries + 1
     Resume start
Else
    If strServer <> "AlternateServer" Then
        strServer = "AlternateServer"
        strUserName = "AlternateUser"
        strPassword = "AlternatePassword"
        intRetries = 0
        Resume start
    End If
End If

CDOSend = Err.Number & Err.Description
Resume exithere
End Function

Another option: send the report as snp and place a link to snp Viewer in the message body...

HTH


[pipe]
Daniel Vlas
Systems Consultant

 
Thanks I found some code that converts a snapshot to pdf after the snapshot is saved to a file.

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Hi Lonnie

I am about create a report which need to be sent to customers by email and I was planning to convert it to PDF format prior to sending.

I was wondering where you found your code that converts a snapshot to pdf. Could you post a reference to it?

Many thanks.

Chop Suey
 
Did you find a solution to this yet. I have a very simple demo I can send you. Email me at lcjohnson at yahoo.com
(I didn't write out the address because they don't like you putting them in this forum)

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Hi Lonnie

I found a solution at Leban's website which creates a snapshot of the report, splits the pages and turns them into a PDF. Is this what you found? Very elegant!

Am currently coding and hoping this will be a viable solution as it does not incur a hefty investment in PDF software for me - I write software for small businesses that run swimming schools and dance studios which are not particularly cash rich!

If I get stuck I will certainly email you.

Thanks for replying!

Chop Suey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top