Msaccess e stampa automatica in file PDF

Anonimo
2012-10-09T12:53:51+00:00

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

Microsoft 365 e Office | Access | Per la casa | Windows

Domanda bloccata. Questa domanda è stata eseguita dalla community del supporto tecnico Microsoft. È possibile votare se è utile, ma non è possibile aggiungere commenti o risposte o seguire la domanda.

0 commenti Nessun commento

Risposta accettata dall'autore della domanda

Anonimo
2012-10-09T14:23:53+00:00

Ciao pfmarro,

fai in questo modo: nel percorso C:\Programmi\PdfCreator\COM\Ms Office trovi un modulo bas con un'esempio di stampa. Non apre finestre di richiesta di alcun tipo in quanto tutto è codificato.

Nel caso in cui dovesse ripresentarsi il blocco prova a verificare se in quel momento resta attivo il processo di pdfcreator nel taskmanager. Nel caso, qui http://www.archivum.info/microsoft.public.it.office.access/2009-05/00476/Re-PDF-Creator.html trovi una variante del tuo codice che elimina, se presente, il processo di pdfcreator prima di lanciare la stampa.

Volendo cambiare completamente genere, in passato ho spesso usatoil modulo di Lebans, che trovi qui http://www.lebans.com/reporttopdf.htm

Personalmente non ho mai riscontrato problemi.

David

La risposta è stata utile?

0 commenti Nessun commento

1 risposta aggiuntiva

Ordina per: Più utili
  1. Anonimo
    2012-10-09T14:08:20+00:00

    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

    <cut>

    Per favore, definisci quando: "a volte si piantano", grazie.

    Sulla stessa macchina?

    Su macchine diverse?

    La risposta è stata utile?

    0 commenti Nessun commento