Connecting Tech Pros Worldwide Forums | Help | Site Map

Sending a pdf file to default printer from vba

cantelow@csd.net
Guest
 
Posts: n/a
#1: Nov 13 '05
Hi folks.

I've got a need to print a preexisting pdf file after an Access report,
as a pseudo attachment.

Seems it should be easy, but how do I send a pdf file to the default
printer? Do I need to run something from shell()? A pointer to the
name of a command to use would be very appreciated- then I would be
armed with a good keyword to use in google, heh.

Thanks!
Ann


cantelow@csd.net
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Sending a pdf file to default printer from vba


This is Access 97, I should have mentioned. Also, I have pdf995
installed, wonder if I should try to find a way to use that from the
command line.
--Thanks.

Tom van Stiphout
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Sending a pdf file to default printer from vba


On 3 Mar 2005 14:40:54 -0800, cantelow@csd.net wrote:

Actually, if you use the ShellExecute Windows API with the "Print"
verb, that should work wonderfully.

-Tom.

[color=blue]
>Hi folks.
>
>I've got a need to print a preexisting pdf file after an Access report,
>as a pseudo attachment.
>
>Seems it should be easy, but how do I send a pdf file to the default
>printer? Do I need to run something from shell()? A pointer to the
>name of a command to use would be very appreciated- then I would be
>armed with a good keyword to use in google, heh.
>
>Thanks!
>Ann[/color]

cantelow@csd.net
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Sending a pdf file to default printer from vba


Thanks, Tom!

Yep, that has handled it for me.

I needed this API declare:

Private Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

-And in my routine, this call printed the file:

Dim lRet as long

lRet = ShellExecute(0, "print", "c:\(path to file)\(filename.pdf)", _
"", "", 1)

If lRet is 2, it apparently means file not found. I got the value of
31 when I had the parameters in the wrong positions. 32 and more means
success.

I think it's likely that it used adobe to print this on my machine,
since I also have that installed. I believe it looks at the default
app for pdf extension to decide what to do for "print".

This will also print .doc and .txt files. It brings up a separate
temporary window for each of those, but I believe that can be controled
with the last parameter to the call.

"Print" is not a command that can be run first from the dos prompt to
test, that doesn't appear to make sense. My poor understanding of what
apis actually are had me trying that for a small while.

Thanks heaps, I'm in business.
-Ann

Closed Thread