Report in PDF format

uplink600

Registered User.
Local time
Today, 20:46
Joined
Mar 18, 2004
Messages
69
Good Morning

I have a button on a form that runs a query and produces a report with the relevant records on it.

Is there an easy way to set this up so that the report is produced in PDF format and then possibly automatically emailed to predefined recipients.

I would appreciate any help and I can advise further details if required.

Regards

VC
 
Hi

The following code may be of use to you here although my example will output to RTF as don't have facility to print to PDF (although is now pretty standard in Office 2007). You would have to adjust the e-mail addresses manually but there are other clever ways of populating the circulation list. I found this code on the forum somewhere and it's proved invaluable (apologies misplaced original author details).

This module can then be inserted where you want and best thing about it is that it doesn't require Outlook to be open - I actually put it into Windows Scheduler to automatically run each day at a certain time.


Hope this helps....

Option Compare Database

Public Function Email_CDO_Test()

Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM

'Dim strDocName As String
'Dim strFilter As String
Dim strOutputDir As String
Dim strDefaultDB As String

'Get current value of default directory ie where access stores files on PC, so that you can reset it after
'you are finished
strDefaultDB = GetOption("Default Database Directory")

'Set the output directory to YOUR_DIRECTORY_HERE and see below when set back to default
strOutputDir = "C:\YourDatabase"
SetOption "Default Database Directory", strOutputDir

'Output report as .RTF file and automatically open word to view
'This does not have to be output to Word, it is just the example
'in my case
'DoCmd.OutputTo acOutputReport, , acFormatRTF, , -1


Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Report"
objMessage.From = """Action Log"" <enter sender e-mail address here>"
objMessage.To = "enter recepient e-mail address here and add others if you wish but separate using a semi colon"
objMessage.TextBody = "Report" & vbCrLf & vbCrLf & "Please find report attached" & vbCrLf & "This is an automated message - please do not reply"

'You can change format to pdf at this point
DoCmd.OutputTo acOutputReport, "YourReport", acFormatRTF, "YourReport.rtf", False
objMessage.AddAttachment "C:\YourDatabase\YourReport.rtf"


'Set the output directory back to its original value
SetOption "Default Database Directory", strDefaultDB


'==This section provides the configuration information for the remote SMTP server.

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "enter your server name here"


'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send

End Function
 

Users who are viewing this thread

Back
Top Bottom