Solved Open Printer in PDF Option

sergio vieira

Member
Local time
Today, 21:16
Joined
Apr 22, 2024
Messages
35
Good afternoon. I don't know if my question is relevant, but I would like to know if it is possible when sending a document to the printer, instead of opening it with the local printer, to open it with the Microsoft PrintToPDF option. Thank you for your help.
 
Look at changing current printer.
Google it or ask ChatGPT
 
Good afternoon. I don't know if my question is relevant, but I would like to know if it is possible when sending a document to the printer, instead of opening it with the local printer, to open it with the Microsoft PrintToPDF option. Thank you for your help.
Hi. You're asking an Access forum and you specifically chose the Form section. Exactly what sort of "document" are you sending to the printer and how exactly are you doing it? Just wondering if you're looking for an Access-related solution.
 
Well, I'm working with access 2003. I want to send a report directly to the printer to be printed as a PDF. I don´t know if its possible?
 
Well, I'm working with access 2003. I want to send a report directly to the printer to be printed as a PDF. I don´t know if its possible?
It will be if you select the printer Microsoft Print To PDF before you open the report for printing.
Store the current printer and restore after the report has been printed.

Could even search here?
 
Wouldn't need to do that if you upgraded Access. OutputTo method can create PDF. Upgrading can be cheap. I bought Office Pro Plus 2021 for $20.

Do you really need to stay with 2003?
 
Here is how chatgpt says you can do it.
Code:
Sub PrintReportToPDF()
    Dim currentPrinter As String
    Dim reportName As String
    Dim pdfFileName As String
    
    ' Save the current printer name
    currentPrinter = Application.Printer.DeviceName
    
    ' Specify the report name and the desired PDF file path
    reportName = "YourReportName"  ' Replace with your report name
    pdfFileName = "C:\path\to\your\output\file.pdf"  ' Replace with your desired file path
    
    ' Set the printer to "Microsoft Print to PDF"
    Application.Printer = Application.Printers("Microsoft Print to PDF")
    
    ' Set the file path to save the PDF
    ' We need to use the Printer object's properties to save the file
    Application.Printer.DefaultFileName = pdfFileName
    
    ' Print the report
    DoCmd.OpenReport reportName, acViewNormal
    
    ' Wait until the report is printed before restoring the printer
    DoEvents
    
    ' Restore the original printer
    Application.Printer = Application.Printers(currentPrinter)
    
    MsgBox "Report printed to PDF successfully!"
End Sub
 
Well, I'm working with access 2003. I want to send a report directly to the printer to be printed as a PDF. I don´t know if its possible?
Thanks, but that's still a bit confusing. Printers don't produce PDF files; rather, they produce hard copy printouts on paper. To create a PDF means you end up with a file, and you won't need an actual printer then; instead, all you need is a printer driver to produce the PDF file.

As already mentioned, Report output to PDF is already included in newer versions of Access. Otherwise, you'll need a separate DLL file to get it done in 2003.
 
You could direct your report to the "print to PDF" device that's native to both windows 10 and windows 11. That would save a report in PDF format. Once saved you could print it. This could be done maybe behind one button. Granted it's convoluted.
 
I created my Bibby Gazette DB in 2003.
Then I had to copy a report to be the name of the ship or date and print it that way.
I had previously set my printer manually to a pdf print emulator like Microsoft print to PDF.

I then switched it back when all the reports were produced.

Once I got hold of 2007, I could of course just create a pdf file.

Code:
Private Sub cmdShip_Click()
On Error GoTo Err_cmdShip_Click

    Dim stRptName As String, stParam As String, stLinkCriteria As String, stDBpath As String, stFTPpath As String
    Dim iPreview As Integer, iDialog As Integer, blnPrintIt As Boolean
    
    stDBpath = CurrentProject.Path & "\"
    stFTPpath = stDBpath & "Gazette\"
    iPreview = acViewPreview
    If Me.ChkPreview Then
       ' iPreview = 2
        iDialog = acWindowNormal
    Else
        iDialog = acHidden
    End If
    
    stRptName = "Main_by_Ship"
    
    stParam = Replace(LCase(Me.cboShip.Value), " ", "_")
    stLinkCriteria = "[Ship] = '" & Me.cboShip.Value & "'"
    
    'DoCmd.CopyObject , stParam, acReport, stRptName
        
    If Me.ChkPreview Then
        DoCmd.OpenReport stRptName, iPreview, , stLinkCriteria, iDialog
    Else
        DoCmd.OpenReport stRptName, iPreview, , stLinkCriteria, iDialog
        DoCmd.OutputTo acOutputReport, stRptName, acFormatPDF, stFTPpath & stParam & ".pdf", False
        DoCmd.Close acReport, stRptName
    End If
    'DoCmd.DeleteObject acReport, stParam

Exit_cmdShip_Click:
    Exit Sub

Err_cmdShip_Click:
    MsgBox Err.Description
    Resume Exit_cmdShip_Click
    
End Sub
 
Here's a report form I frequently use in my apps. It allows you to define arguments for each report and this form changes the visible fields as you click on different reports. It also supports multiple output destinations. The PDF option prints to PDF but you can change it to open the PDF without saving if you prefer or add a 5th option so you can have both.
1743178833261.png
 

Attachments

Users who are viewing this thread

Back
Top Bottom