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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically save report to PDF with a twist!

Status
Not open for further replies.

YoBi4Ever

Instructor
Joined
Jun 5, 2007
Messages
18
Location
KW
Hi,

I've read many posting and I'm able to save Access reports, however, even though I type the path and the file name I'm still prompted for these info! I would like to have the report saved automatically. Any ideas PLEASE?

The following is one of the solutions I used: thread705-1182605

'#######################################################
Option Compare Database
Option Explicit

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Const maxTime = 10 ' in seconds
Private Const sleepTime = 250 ' in milliseconds

Public Function PrintPDF(ByVal rptName As String, ByVal sFilterCriteria As String, Optional sAutoSaveDirectory As String, Optional sAutoSaveFileName As String) As Boolean

'initialise
On Error GoTo err_Error
Dim clsPDF As PDFCreator.clsPDFCreator 'Initialise the PDF class
Dim strDefaultPrinter As String
Dim strOutputFileName As String
Dim strSaveDirectory As String
Dim i As Long

'set the success variable to true here but it will be set to
'false if the function fails at any point
PrintPDF = True

Set clsPDF = New clsPDFCreator

With clsPDF
.cStart "/NoProcessingAtStartup"
.cOption("UseAutosave") = 1 '1 = True, 0 = False

If sAutoSaveDirectory = "" Then
.cOption("UseAutosaveDirectory") = 0
Else
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sAutoSaveDirectory
End If

If sAutoSaveFileName = "" Then
.cOption("AutosaveFileName") = rptName
Else
.cOption("AutosaveFileName") = sAutoSaveFileName
End If

.cOption("AutosaveFormat") = 0 '0 = PDF
'strDefaultPrinter = .cDefaultPrinter
'.cDefaultPrinter = "PDFCreator"
.cClearCache
Sleep 1
DoCmd.OpenReport rptName, acViewNormal, , sFilterCriteria
.cPrinterStop = False
End With

i = 0

Do While (clsPDF.cOutputFilename = "") And (i < (maxTime * 1000 / sleepTime))
i = i + 1
Sleep 500
Loop

strOutputFileName = clsPDF.cOutputFilename

With clsPDF
'.cDefaultPrinter = strDefaultPrinter
'Sleep 200
.cClose
End With

If strOutputFileName = "" Then
' MsgBox "Creating pdf file." & vbCrLf & vbCrLf & _
' "An error has occured: Time is up!", vbExclamation + vbSystemModal
PrintPDF = False
Call HandleError("Report " & sAutoSaveFileName & " did not print", "modPDFPrinter_PrintPDF")
End If

'error handler and exit
err_Exit:
Set clsPDF = Nothing
Exit Function
err_Error:
PrintPDF = False
MsgBox Err.Description
Call HandleError(Err.Description, "modPDFPrinter_PrintPDF")
Resume err_Exit
Resume

End Function

'#######################################################

Call PrintPDF("rptInventory", "", "c:\test", "inventorypdf.pdf")

 
It works for me and even creates a directory if it does not exist. Have you downloaded the latest version of PDFCreator? Does c:\test exist, and if not, does the user have permissions for C:\ ?
 
Yes, they all exist!!!
I went to adobe pdfwriter under pritners and changed some settings and it worked! I don't see the relationship but it worked.
 
There are those commented lines ... ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top