premesso che uso Access 2003
c'e' un modo per automatizzare la stampa di un report di access in un file PDF senza che debba aprirsi la maschera per mettere nome e path?
ho trovato alcuni esempi con pdfcreator
http://www.vbaexpress.com/forum/showthread.php?t=14397
http://grenier.self-access.com/?post/2008/05/07/Automatiser-limpression-dun-etat-en-PDF-via-PDFCreator
ma a volte si piantano
- o vanno in timeout
- oppure impossibile aprie l'oggetto pdfcreator
Grazie anticipatamente
PFMarro
'
' fonte:
' http://www.vbaexpress.com/forum/showthread.php?t=14397
'
Public Sub pfmPrintAccessReportToPDF_Early(sPDFName As String)
Dim pdfjob As PDFCreator.clsPDFCreator
' Dim sPDFName As String
Dim sPDFPath As String
Dim sPrinterName As String
Dim sReportName As String
Dim lPrinters As Long
Dim lPrinterCurrent As Long
Dim lPrinterPDF As Long
Dim prtDefault As Printer
Dim sReportName1 As String
'/// Change the report and output file name here! ///
' sReportName = "rpt_Employee"
sReportName = "PFMsample"
sReportName1 = "rpt_Employee_1"
sPDFName = "EmployeeList_" & Format(Date, "yyyymmdd") & ".pdf"
' sPDFPath = "C:\Local\Data\mr97856\Reports" 'EmployeeList_" & Format(Date, "yyyymmdd")
sPDFPath = CurrentProject.Path & "" 'EmployeeList_" & Format(Date, "yyyymmdd")
'Resolve index number of printers to allow changing and preserving
sPrinterName = Application.Printer.DeviceName
On Error Resume Next
For lPrinters = 0 To Application.Printers.Count
Set Application.Printer = Application.Printers(lPrinters)
Set prtDefault = Application.Printer
Select Case prtDefault.DeviceName
Case Is = sPrinterName
lPrinterCurrent = lPrinters
Case Is = "PDFCreator"
lPrinterPDF = lPrinters
Case Else
'do nothing
End Select
Next lPrinters
On Error GoTo 0
'Change the default printer
Set Application.Printer = Application.Printers(lPrinterPDF)
Set prtDefault = Application.Printer
'Start PFF Creator
Set pdfjob = New PDFCreator.clsPDFCreator
With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "PrtPDFCreator"
Exit Sub
End If
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
'Print the document to PDF
DoCmd.OpenReport (sReportName)
'DoCmd.OpenReport (sReportName1)
'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
'pdfjob.cPrinterStop = False
'Combine all PDFs into a single file and stop the printer
With pdfjob
.cCombineAll
.cPrinterStop = False
End With
'Wait until PDF creator is finished then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
pdfjob.cClose
'Reset the (original) default printer and release PDF Creator
Set Application.Printer = Application.Printers(lPrinterCurrent)
Set pdfjob = Nothing
End Sub