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")
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")