Re: Open/print PDF-file from Access



Solution is to wait 1 second before closing Adobe.
Window not found because not open yet !

Thanks


"Filips Benoit" <benoit.filips@xxxxxxxxxx> wrote in message
news:5aWsi.33411$f_7.1039430@xxxxxxxxxxxxxxxxxxxxxxxx
Sorry Tom,

But can't find the main window of Adobe Reader 7.0 .
I have found several window-names for Adobe Reader but none is matching !
Or, like most cases I'll must have made some stupidity but can't see it !

Can you send my those 2(?) lines.

Thanks,

Filip

****************************** tested code ****************************
Option Compare Database
Option Explicit
Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long

Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Private Declare Function PostMessage Lib "user32" _
Alias "PostMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long

Private Declare Function IsWindow Lib "user32" _
(ByVal hwnd As Long) As Long

Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long

Private Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hwnd As Long, _
lpdwProcessId As Long) As Long

'Constants that are used by the API
Const WM_CLOSE = &H10
Const INFINITE = &HFFFFFFFF
Const SYNCHRONIZE = &H100000

Private Sub Command4_Click()

On Error GoTo errHandling

Dim ret As Variant
ret = ShellExecute(0, "print", "c:\adobe.pdf", vbNullString, 0, 0)

DoCmd.Hourglass True

Dim hWindow As Long
Dim hThread As Long
Dim hProcess As Long
Dim lProcessId As Long
Dim lngResult As Long
Dim lngReturnValue As Long
Dim iLoop As Long

Do While hWindow = 0
iLoop = iLoop + 1
hWindow = FindWindow(vbNullString, "Adobe Reader-[adobe.pdf]")
If hWindow = 0 Then hWindow = FindWindow(vbNullString, "Adobe
Reader - [adobe.pdf]")
If hWindow = 0 Then hWindow = FindWindow(vbNullString, "Adobe
Reader")
If hWindow = 0 Then hWindow = FindWindow(vbNullString, "Adobe
Acrobat")
If hWindow = 0 Then hWindow = FindWindow("AVL_AVPopup", "")
If iLoop > 50 Then Exit Do
Loop

MsgBox hWindow

hThread = GetWindowThreadProcessId(hWindow, lProcessId)
hProcess = OpenProcess(SYNCHRONIZE, 0&, lProcessId)
lngReturnValue = PostMessage(hWindow, WM_CLOSE, 0&, 0&)
lngResult = WaitForSingleObject(hProcess, INFINITE)
DoCmd.Hourglass False

Exit Sub

errHandling:

DoCmd.Hourglass False
MsgBox err.Number & " " & err.Description

End Sub
*******************************************************************************************




"Tom van Stiphout" <no.spam.tom7744@xxxxxxx> wrote in message
news:i2r7b31v2jqqkiiutf21juf812urau9e0j@xxxxxxxxxx
On Fri, 03 Aug 2007 15:54:22 GMT, "Filips Benoit"
<benoit.filips@xxxxxxxxxx> wrote:

That's annoying, but with 2 more lines of code you can find the window
handle of the main window of that application (FindWindow), and send
it a WM_CLOSE message (PostMessage).

-Tom.


OK, works fine but it opens acrobat without closing it !

Filip


"Tom van Stiphout" <no.spam.tom7744@xxxxxxx> wrote in message
news:kge6b3p6a0849gg8na3v9k916gdbuccls4@xxxxxxxxxx
On Fri, 03 Aug 2007 10:43:28 GMT, "Filips Benoit"
<benoit.filips@xxxxxxxxxx> wrote:

I would use a 1-liner: use the ShellExecute API with the Print verb.
That would be the equivalent of dropping the PDF file on the Default
Printer icon. Windows will invoke the registered app and tell it you
wanted to print that file.

-Tom.


Dear All,

All 3 codes, copied from internet, triggers error 429 : ActiveX
component
can't create object !
No compile error.
I have the reference set to Adobe Acrobat 7.0 Type Library
I do not have the full version of Adobe Reader 7.0 !

The final goal is to print a PDF-file from access after selecting the
file
in a browser.

Please help!

Filip

------------------------------------------------------------------
Private Sub Command0_Click()

Dim gApp As Acrobat.Acroapp
Dim gPDdoc As Acrobat.AcroPDDoc

Dim jso As Object
gApp = CreateObject("AcroExch.App")
gPDdoc = CreateObject("AcroExch.PDDoc")
If gPDdoc.Open("c:\adobe.pdf") Then
jso.gPDdoc.GetJSObject
jso.console.Show
jso.console.Clear
jso.console.println ("Hello, Adobe !")
gApp.Show
End If

End Sub
------------------------------------------------------------------
Private Sub Command1_Click()

Dim Acroapp As CAcroApp
Dim avFile As CAcroAVDoc
Dim jso As Object
'Start Acrobat in the background
Set Acroapp = CreateObject("AcroExch.App")

'Uncomment the following line if you want to watch the program run
Acroapp.Show

Set avFile = CreateObject("AcroExch.PDDoc") 'This is the code file

'Open the already created code file
If avFile.Open("c:\adobe.pdf", "PDFfilip") Then
jso.gPDdoc.GetJSObject
jso.console.Show
jso.console.Clear
jso.console.println ("Hello, Adobe !")
Acroapp.Show
End If
End Sub
------------------------------------------------------------------
Private Sub Command2_Click()

Dim AcroExchApp As Object
Dim AcroExchPDDoc As Object

Set AcroExchApp = CreateObject("AcroExch.App")
Set AcroExchPDDoc = CreateObject("AcroExch.PDDoc")

' Show the Acrobat Exchange window
AcroExchApp.Show

AcroExchPDDoc.Open "c:\adobe.pdf"
AcroExchPDDoc.PrintOut

' Close the PDDoc
AcroExchPDDoc.Close

' Close Acrobat Exchange
AcroExchApp.Exit

End Sub
------------------------------------------------------------------








.



Relevant Pages

  • Re: Are VBA userforms always child of Windows desktop?
    ... Private Declare Function GetDesktopWindow Lib "user32" As Long ... Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long ... The system restores the window to its original state. ... Dim hWndDesktop As Long ...
    (microsoft.public.excel.programming)
  • Re: ColorIndex of the current application
    ... the VBE window even with Ctrl-Alt-Delete, will have to reboot in a moment! ... Private Declare Function GetCursorPos Lib "user32" (_ ... Dim ctr As CommandBarPopup ...
    (microsoft.public.excel.programming)
  • Re: ColorIndex of the current application
    ... Private Declare Function GetCursorPos Lib "user32" (_ ... Dim ctr As CommandBarPopup ... containing Window, rather than the screen? ...
    (microsoft.public.excel.programming)
  • Re: ColorIndex of the current application
    ... Private Declare Function GetCursorPos Lib "user32" (_ ... Dim ctr As CommandBarPopup ... containing Window, rather than the screen? ...
    (microsoft.public.excel.programming)
  • Returning selected items in an open folder
    ... items in an open folder window. ... Dim boo As Boolean ... '-- s1 is a unique string that's part of a specific open folder path. ... Private Sub Form_QueryUnload ...
    (microsoft.public.vb.general.discussion)