pdf Created From Report Does Not Appear on Top of Form (1 Viewer)

curtisB

New member
Local time
Today, 14:30
Joined
Nov 30, 2021
Messages
9
I have a small network with two PCs, each running Access 2019. They have identical front end .accdb files
and both are linked to the same back end .accdb file. Each runs the following VBA code to create a pdf file
from an Access report:

Code:
DoCmd.OutputTo acOutputReport, "rptCustomerQuote", acFormatPDF, "CustomerQuote.pdf", True

When PC #1 runs this code the pdf file is generated and appears on top of the Access form, which is what I want to happen.
But when PC #2 runs the code the pdf file is generated but DOES NOT appear on top of the form. I can't see the pdf file by minimizing
the Access window or by cycling through any open windows by doing ALT + TAB. But when I close Access the pdf appears.

On both PCs, Adobe Acrobat DC is the default application for opening pdf files. I opened Adobe Acrobat PC and checked preferences,
but I couldn't see an option for forcing the document to appear on top of other windows.

I don't know if the problem is with my VBA code, or if it has to do with Adobe Acrobat DC's settings.

Any suggestions would be appreciated.

Thank you.
 

Ranman256

Well-known member
Local time
Today, 15:30
Joined
Apr 9, 2015
Messages
4,337
PDF may be controlled by the pdf printer setup. Some have a flag to open the pdf when it’s created.
see if it’s checked.
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:30
Joined
Sep 21, 2011
Messages
14,260
I cannot see it being your code, as the same code works on the other PC?
It will be a setting somewhere or a windows update.
Compare windows versions

Recently when I open an Outlook email, it no longer goes to the front of outlook, but remains behind the outlook window?
 

curtisB

New member
Local time
Today, 14:30
Joined
Nov 30, 2021
Messages
9
PDF may be controlled by the pdf printer setup. Some have a flag to open the pdf when it’s created.
see if it’s checked.
Thanks for the suggestion. Both PCs print to the same network printer. I don't know if each PC has its own printer settings, or if the two PCs use the same settings assigned to the printer.

Would the printer settings affect the pdf document that appears on screen, or just what's sent to the printer?

In general, the users don't print the pdf. They just view the pdf, and might print it later. I would like the pdf document to appear on top of the Access form, but on one of the PCs it doesn't, and in fact doesn't appear until I've closed Access.
 

sxschech

Registered User.
Local time
Today, 12:30
Joined
Mar 2, 2010
Messages
792
Another idea to try. Instead of setting the output to TRUE set it to FALSE and then use followhyperlink to open the file something like:

Code:
DoCmd.OutputTo acOutputReport, "rptCustomerQuote", acFormatPDF, "CustomerQuote.pdf",False

Application.FollowHyperlink "C:\Reports\CustomerQuote.pdf"
 

curtisB

New member
Local time
Today, 14:30
Joined
Nov 30, 2021
Messages
9
Another idea to try. Instead of setting the output to TRUE set it to FALSE and then use followhyperlink to open the file something like:

Code:
DoCmd.OutputTo acOutputReport, "rptCustomerQuote", acFormatPDF, "CustomerQuote.pdf",False

Application.FollowHyperlink "C:\Reports\CustomerQuote.pdf"
That's a good suggestion. I'll try it and let you know the outcome.
Thanks.
 

curtisB

New member
Local time
Today, 14:30
Joined
Nov 30, 2021
Messages
9
That's a good suggestion. I'll try it and let you know the outcome.
Thanks.
Hi,
I finally had a chance to try it, but unfortunately it didn't help.

But I have a new piece information that may help. PC #1, which displays the pdf file on top of the Access form
is running Adobe Acrobat DC Standard 32 bit. But PC #2, which does not display the pdf file until after Access is closed,
is running Adobe Acrobat DC Pro 32 bit. Perhaps Acrobat DC Pro has a default behavior for displaying documents that is
different than Acrobat DC Standard. Maybe there's a setting in the Preferences section that controls this. But I can't tell
which it is, and I'd prefer not to randomly change settings without knowing the effect.

Any suggestions would be deeply appreciated. (I guess I could visit an Adobe Acrobat forum.)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:30
Joined
May 7, 2009
Messages
19,230
you may try setting the focus to the app using API?
copy this in a New Module:
Code:
' Module Name: ModFindWindowLike
' (c) 2005 Wayne Phillips (http://www.everythingaccess.com)
' Written 02/06/2005
'
' mODIFIED bY aRNELgP FOR x64 aCCESS
'
              
#If VBA7 Then
    Private Declare PtrSafe Function EnumWindows Lib "user32" (ByVal lpEnumFunc As LongPtr, ByVal lParam As LongPtr) As Long
    Private Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As LongPtr, ByVal lpString As String, ByVal cch As Long) As Long
    
        'Could use global variables instead, but this is nicer.
        'Custom structure for passing in the parameters in/out of the hook enumeration function
        'Could use global variables instead, but this is nicer.
        Private Type FindWindowParameters
    
            strTitle As String  'INPUT
            hWnd As LongPtr     'OUTPUT
    
        End Type
#Else
                
    Private Declare Function EnumWindows Lib "user32" _
       (ByVal lpEnumFunc As Long, _
        ByVal lParam As Long) As Long
 
    Private Declare Function GetWindowText Lib "user32" _
        Alias "GetWindowTextA" _
       (ByVal hwnd As Long, _
        ByVal lpString As String, _
        ByVal cch As Long) As Long
        'Could use global variables instead, but this is nicer.
        'Custom structure for passing in the parameters in/out of the hook enumeration function
        'Could use global variables instead, but this is nicer.
        Private Type FindWindowParameters
    
            strTitle As String  'INPUT
            hWnd As Long        'OUTPUT
    
        End Type
#End If

'''experimental''''''''''''''''
Private Const WM_CHAR = &H102
Private Const BM_CLICK As Long = &HF5&

''' close the window
Private Const WM_SYSCOMMAND = &H112
Private Const SC_CLOSE = &HF060

#If VBA7 Then
Private Declare PtrSafe Function SendMessageBynum Lib "user32" Alias "SendMessageA" (ByVal hWnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
Private Declare PtrSafe Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As Long

#Else
private Declare Function SendMessageBynum Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As any) 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
#End If
'''''''''''''''''''''



#If VBA7 Then
Public Function FnFindWindowLike(strWindowTitle As String) As LongPtr

#Else
Public Function FnFindWindowLike(strWindowTitle As String) As Long
#End If
 
    'We'll pass a custom structure in as the parameter to store our result...
    Dim Parameters As FindWindowParameters
    Parameters.strTitle = UCase(strWindowTitle) ' Input parameter
 

#If VBA7 Then
    Call EnumWindows(AddressOf EnumWindowProc, VarPtr(Parameters))
#Else
    Call EnumWindows(AddressOf EnumWindowProc, VarPtr(Parameters))
#End If
    FnFindWindowLike = Parameters.hWnd
 
End Function

#If VBA7 Then
Private Function EnumWindowProc(ByVal hWnd As LongPtr, _
                               lParam As FindWindowParameters) As LongPtr
#Else
Private Function EnumWindowProc(ByVal hWnd As Long, _
                               lParam As FindWindowParameters) As Long
#End If
   Dim strWindowTitle As String

   strWindowTitle = Space(260)
   Call GetWindowText(hWnd, strWindowTitle, 260)
   strWindowTitle = UCase(TrimNull(strWindowTitle)) ' Remove extra null terminator
                                      
   If strWindowTitle Like lParam.strTitle Then

        lParam.hWnd = hWnd 'Store the result for later.
        EnumWindowProc = 0 'This will stop enumerating more windows

   Else

        EnumWindowProc = 1

   End If
                      
End Function

Private Function TrimNull(strNullTerminatedString As String)

    Dim lngPos As Long

    'Remove unnecessary null terminator
 
    lngPos = InStr(strNullTerminatedString, Chr$(0))

    If lngPos Then
        TrimNull = Left$(strNullTerminatedString, lngPos - 1)
    Else
        TrimNull = strNullTerminatedString
    End If
   'Debug.Print TrimNull
End Function

on your code that output/display the pdf add this API declaration:
Code:
Option Compare Database
Option Explicit

#If VBA7 Then
    Private Declare PtrSafe Function SetForegroundWindow Lib "user32" _
        (ByVal hWnd As LongPtr) As Long
#Else
    Private Declare Function SetForegroundWindow Lib "user32" _
        (ByVal hWnd As Long) As Long
#End If

on your OutputTo code:
Code:
#If VBA7 Then
Dim hW As LongPtr
#Else
Dim hW As Long
#End If
DoCmd.OutputTo acOutputReport, "rptCustomerQuote", acFormatPDF, "CustomerQuote.pdf",False
Application.FollowHyperlink "C:\Reports\CustomerQuote.pdf"
DoEvents
hW = FnFindWindowLike("*CustomerQuote*")
If (hW <> 0) Then
    SetForegroundWindow hW
End If
/CODE]
 

Users who are viewing this thread

Top Bottom