Print File to Specific Printer (1 Viewer)

MattBaldry

Self Taught, Learn from the Forums
Local time
Today, 09:23
Joined
Feb 5, 2019
Messages
293
Hi All,

I have just finished a form the allows me to open saved pdf files and it works great.

Is there simple code to direct print these to a specific printer?

I have looked but lost the link that I found that I thought would do it and cannot find it anymore.

~Matt
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:23
Joined
May 7, 2009
Messages
19,243
docmd.RunCommand acCmdPrint

it will show a dialog and you can choose which printer to use.
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:23
Joined
Sep 21, 2011
Messages
14,301
Have search here. That has been asked several times.
Also see similar threads.
 

MattBaldry

Self Taught, Learn from the Forums
Local time
Today, 09:23
Joined
Feb 5, 2019
Messages
293
docmd.RunCommand acCmdPrint

it will show a dialog and you can choose which printer to use.
Hi Arnelgp,

Sorry, I think I worded it wrong. I don't want to open the print dialog. I want the VBA code to decide on the printer.

I want the user to be able to double click the list box and it will print the selected PDF to the printer set in the VBA.

Please note, this is an external file from access. It would be a PDF file saved in a shared storage device folder.

~Matt
 

MattBaldry

Self Taught, Learn from the Forums
Local time
Today, 09:23
Joined
Feb 5, 2019
Messages
293
docmd.RunCommand acCmdPrint

it will show a dialog and you can choose which printer to use.
Hi arnelgp,

I have found your old code below, but need to find a way of setting the printer this needs to output to.

Code:
Public Sub PrintAnyDocument(ByVal strPathFile As String)
    Dim TargetFolder
    Dim FileName
    Dim ObjShell As Object
    Dim ObjFolder As Object
    Dim ObjItem As Object
    Dim ColItems As Object
    
    If InStrRev(strPathFile, "\") <> 0 Then
        TargetFolder = Left(strPathFile, InStrRev(strPathFile, "\"))
        FileName = Right(strPathFile, Len(strPathFile) - Len(TargetFolder))
    End If
    Set ObjShell = CreateObject("Shell.Application")
    Set ObjFolder = ObjShell.NameSpace(TargetFolder)
    Set ColItems = ObjFolder.Items
    For Each ObjItem In ColItems
        If ObjItem.Name = FileName Then
            ObjItem.InvokeVerbEx ("Print")
            Exit For
        End If
    Next
    Set ObjItem = Nothing
    Set ColItems = Nothing
    Set ObjFolder = Nothing
    Set ObjShell = Nothing
End Sub

Would this be possible?

~Matt
 

sonic8

AWF VIP
Local time
Today, 10:23
Joined
Oct 27, 2015
Messages
998
The PrintTo verb should allow you to pass the desired printer name as argument.
 

sonic8

AWF VIP
Local time
Today, 10:23
Joined
Oct 27, 2015
Messages
998
@Gasman , how does that apply to printing existing PDF files from the file system?
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:23
Joined
Sep 21, 2011
Messages
14,301
@Gasman , how does that apply to printing existing PDF files from the file system?
I was concentrating on selecting a certain printer?

Adding some words I found this by arnelgp also via google

 

sonic8

AWF VIP
Local time
Today, 10:23
Joined
Oct 27, 2015
Messages
998
I was concentrating on selecting a certain printer?
Unfortunately, the process of selecting a printer for printing an Access report is entirely different from selecting the printer for printing an existing file from the file system.
Unless you can safely assume a certain application being installed, your only option is to use the generic verbs from of the shell and hope there is an application supporting them.
 

MattBaldry

Self Taught, Learn from the Forums
Local time
Today, 09:23
Joined
Feb 5, 2019
Messages
293
Unfortunately, the process of selecting a printer for printing an Access report is entirely different from selecting the printer for printing an existing file from the file system.
Unless you can safely assume a certain application being installed, your only option is to use the generic verbs from of the shell and hope there is an application supporting them.
Thanks sonic8,

For my system they will always be pdf and Adobe reader will always be present. Understand the others may be different, hoping that mine will be easier.

The printer is shared and the same name on all clients, all clients have Adobe Reader present.

The main issue with this would be our default printers are A4 Mono, the one I need to print these files on is A3 Colour.

~Matt
 

sonic8

AWF VIP
Local time
Today, 10:23
Joined
Oct 27, 2015
Messages
998
@MattBaldry , did you try my recommendation regarding the PrintTo verb?

If you can be sure Adobe Reader is installed on every computer, you could also run the print operation from the command line directly invoking Adobe Reader. That's what the PrintTo verb is wrapped around.

IIRC Adobe Reader also has a COM-API that would allow you to automate it. Nonetheless, I would try the above-mentioned options first, as they might be easier and quicker to implement.
 

MattBaldry

Self Taught, Learn from the Forums
Local time
Today, 09:23
Joined
Feb 5, 2019
Messages
293
@MattBaldry , did you try my recommendation regarding the PrintTo verb?

If you can be sure Adobe Reader is installed on every computer, you could also run the print operation from the command line directly invoking Adobe Reader. That's what the PrintTo verb is wrapped around.

IIRC Adobe Reader also has a COM-API that would allow you to automate it. Nonetheless, I would try the above-mentioned options first, as they might be easier and quicker to implement.
Hi Sonic8,

I haven't had a chance to work on it properly. I will work on getting it to print first, then sort the printer issue out.

I will keep you updated :)

~Matt
 

Users who are viewing this thread

Top Bottom