print pdf to a printer - (picking up on another member's post of the last week)

Hi EE,

Requesting help on this recent EE post, please:

Providentially, I am working on the same problem and discovered this dialogue:
A few years ago (a2000) I received from another forum help to print a pdf using sendkeys.

Now, i am using a2003:, and the logic is not working to print the pdf to a real printer.
i followed Cap's advice, yet:
       the system is not understanding the foreground window to be Adobe -
      if i'm in breakpoint mode, it thinks the current window is vba
      if i run not in breakpoint mode (i'm running this mdb like a quasi vbs script),  it thinks it's in
       vbs mode.

     In the code window is code per Cap's instructions.
     AFterwards, the code window shows my old logic that opened pdf for printing, sendkeys
     to print, then closed pdf

     In this environment:
          I need to print to another network printer, so added sendkeys to change printer
          all of sudden the application.hyperlink is popping up a microsoft message box
          so i see that doing a shell to adobe is equivalent.

Please advise, tx, sandra    

   i will open a new post, i just wanted to catch your attention, if you have time....
  tx, sandra
Option Compare Database
Option Explicit
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_CLOSE = &H10
Public lngAdobehWnd As Long
Public Sub TestPDF()
Call g005_PrintPdfByHyperLink("C:\ARG_99_Scripts\ARG_99_DailyElectives_script\AutomatedDailyElectivesListing.pdf", _
                              False, _
End Sub
Public Sub g005_PrintPdfByHyperLink(strFilePath As String, _
                                    blnRunDuringDay As Boolean, _
                                    strBackPrintTestPage As String)
Shell "C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe" & " " & strFilePath
SendKeys "%FP", True
SendKeys "Student Affairs", True
If strBackPrintTestPage = "Y" Then
   SendKeys "{TAB}", True
   SendKeys "{TAB}", True
   SendKeys "{TAB}", True
   SendKeys "{TAB}", True
   SendKeys "1", True    'for testing
End If
SendKeys "{enter}", True
lngAdobehWnd = GetForegroundWindow
'close adobe
Call SendMessage(lngAdobehWnd, WM_CLOSE, 0, 0)
End Sub
Public Sub old_g005_PrintPdfByHyperLink(ByVal strFilePath As String, _
                                          blnRunDuringDay As Boolean, _
                                          strBackPrintTestPage As String)
' opening pdf via adobe
' FilePath is full path of .pdf file to be printed
   ' Application.FollowHyperlink strFilePath
   ' SendKeys "%FP{enter}^q", True
   Shell "C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe" & " " & strFilePath
    If blnRunDuringDay = False Then
'       g_strScreenMsg = "* * Please wait as PDF opens and self-prints * *  "
'       DisplayScreenMsg (enTypeScreenMsg.enTypeScreenInfoMsg)
      ' Allow time for opening of associated
      ' application and stabilization of display
      g010_p_wait 500
      ' Invoke print dialog box (Alt + f + p)
      SendKeys "%fp", True
      ' SendKeys "Diane's printer", True
       SendKeys "Student Affairs", True
      ' Allow time for stabilization
      g010_p_wait 100
      ' Press Enter (This is equivalent to clicking OK
      ' in the print dialog box)
      If strBackPrintTestPage = "Y" Then
         SendKeys "{TAB}", True
         SendKeys "{TAB}", True
         SendKeys "{TAB}", True
         SendKeys "{TAB}", True
         SendKeys "1", True    'for testing
      End If
      SendKeys "{ENTER}", True
      ' Allow time for stabilization
      g010_p_wait 100
      ' Close & Exit pdf application (Alt + f + x)
      SendKeys "^Q", True
'      g_strScreenMsg = "* * Successful Print * * "
'      DisplayScreenMsg (enTypeScreenMsg.enTypeScreenInfoMsg)
'      g_strScreenMsg = "* * Successful Preview * * "
'      DisplayScreenMsg (enTypeScreenMsg.enTypeScreenInfoMsg)
    End If
End Sub
Public Sub g010_p_wait(ByVal Tmr As Long)
' Introduces time delay of Tmr cycles
    Dim Cnt As Long
    For Cnt = 1 To Tmr
End Sub

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeffrey CoachmanMIS LiasonCommented:
I thought the resolution was to not print the PDF, but to simply print the Report.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Why not use Foxit instead. You can print a pdf file with one safe line (without Sendkeys).  I can't imagine why someone would go all the complicity of the code listed and risk compromising computers using send keys when such a simple solution is available.

Sample, to the default printer:
Shell Chr(34) & "C:\Program Files\Foxit Software\Foxit R
eader\Foxit Reader.exe" & Chr(34) & " /p " & Chr(34) & "C:\Documents and Settings\Administrator\My Documents" & Chr(34)

Sample, to a specific printer:
Shell Chr(34) & "C:\Program Files\Foxit Software\Foxit R
eader\Foxit Reader.exe" & Chr(34) & " /t " & Chr(34) & "C:\Documents and Settings\Administrator\My Documents" & Chr(34) & " " & Chr(34) & "Lexmark X5400 Series" & Chr(34)

It is also faster than adobe reader and it is free:
mytfeinAuthor Commented:
Hi guys,
a) I thorougly re-read bartzinc's posts, bec. boag200/Jeff said it was resolved.
I saw that bartzinc printed directly from access and not pdf.
Great, so I modified my code this morning to print from excel and not even open pdf.

b) Before I understood (a), I found a diff. post by TheNelson where he recommends foxit.
    So I downloaded it.  On Fri, I downloaded Adobe updates. Not sure if the updates or foxit
    changed my pc settings regarding Adobe. Pdfs now require me to confirm opening them
    in IE, or when I do an Application.followhyperlink in Access.

    You see, under A2000 i had sendkeys logic for pdf that worked off a form's button.
     Now under A2003, when running as quasi VBS script, the Access mdb has control over
     pdf screen, and sendkeys not working. Before sendkeys, i did an application.followhyperling
     with pdf path to open pdf, but as i said before, now i'm getting a confirm box to open pdf where
      before foxit install, pdf opened seamlessly.

     so I uninstalled foxit...
     so I may have to call IT to reinstall Adobe....

     so am hestitant in using foxit

c) so I explored EE other ideas of doing shell to adobe with pdf path
    (to avoid confirm msg box of Application.hyperlink)
    but, could not determine handle to close pdf.

d) I would be very interested in Capricorn1's idea of determining the handle of pdf
    to issue a close. This would be useful in opening/printing a pdf file that i did not create.
    Our dept has pdfs that other depts created, so i cannot print from its orig. app (for ex: publisher).

e)    that's why although (a) meets my needs for now,
      (d) would be very useful...

f) i googled and fond this to try to make (d) work,
    i pasted the logic from this link into module but it did not work for me...

if you have any ideas on d,e,f that would be great, tx, sandra

10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Foxit did not effect Adobe on my computer.
mytfeinAuthor Commented:
Hi TheNelson,

just wondering:
   a) do you use reader (which vers) ?
   b) do you use adobe pro (which vers)
   c) do you use foxit simply to print via batch, or is foxit your "default" reader
   d) if foxit is just for batch, is your windows explorer setup to open pdf files with Adobe reader
       and not foxit?
  tx, s
mytfeinAuthor Commented:
Hi guys,
I posted yesterday on another forum:

Got a response that recommends this approach:

I have not tried it yet... just sharing... tx, sandra
Reader: 8
Don't use Adobe pro
I now use Foxit it as my default reader.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.