Hi everyone,
I'm not a vba expert so I need help.
I'm using Access 2003 and I need to save a report in a pdf file to send it via email.
On my pc is already installed pdfcreator and in its directory there is an help file modPDFCreatorAccess that contains the code above:
Code:
Attribute VB_Name = "modPDFCreatorAccess"
Option Compare Database
Option Explicit
' Add a reference to PDFCreator
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const maxTime = 10 ' in seconds
Private Const sleepTime = 250 ' in milliseconds
Public Function Start()
PrintRep "Report1"
End Function
Public Sub PrintRep(RepName As String)
Dim PDFCreator1 As PDFCreator.clsPDFCreator, DefaultPrinter As String, c As Long, _
OutputFilename As String
Set PDFCreator1 = New clsPDFCreator
With PDFCreator1
.cStart "/NoProcessingAtStartup"
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = "C:\"
.cOption("AutosaveFilename") = RepName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
DefaultPrinter = .cDefaultPrinter
.cDefaultPrinter = "PDFCreator"
.cClearCache
DoCmd.OpenReport RepName, acViewNormal
.cPrinterStop = False
End With
c = 0
Do While (PDFCreator1.cOutputFilename = "") And (c < (maxTime * 1000 / sleepTime))
c = c + 1
Sleep 200
Loop
OutputFilename = PDFCreator1.cOutputFilename
With PDFCreator1
.cDefaultPrinter = DefaultPrinter
Sleep 200
.cClose
End With
Sleep 2000 ' Wait until PDFCreator is removed from memory
If OutputFilename = "" Then
MsgBox "Creating pdf file." & vbCrLf & vbCrLf & _
"An error is occured: Time is up!", vbExclamation + vbSystemModal
End If
End Sub
In vba I've already added a reference to pdfcreator library, but I don't know exactly how to use this code.
I tried to put it in a module then, on click event of a button, I put "call PrintRep", but the result was an error.
Can you help please to understand how to do?
I tried the Leban's solution, but I see it doesn't work on win 7 machines and I'd rather use pdfcreator.
Thank you very much for help.
Regards.
Remigio