UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> File Opening, But Gets Hidden In The Background Behind Access, Access 2016    
 
   
jabm
post May 22 2020, 10:17 PM
Post#1



Posts: 78
Joined: 29-January 20
From: Londonderry, NH. USA


One last question for the night - thank you all for your patience with me.
I got my textbox on_click event to work so that I can both 1) add the file path to an empty textbox and 2) to open the file noted at the path noted in the text box
(side note: need to ensure that only a file path gets added so need to tighten it up - but that is for another day)

My question is why is the file being opened - in the quick test I did it was a PDF opened properly in Adobe Acrobat Reader - but immediately hidden to behind Access.

I am using this:
Application.FollowHyperlink strFilePath

as found at:
https://answers.microsoft.com/en-us/msoffic...07-9f6f0cb89f1e

Is there a way to have this open the file and have it stay in the foreground?

Thank you and have a Blessed night! :-)
Go to the top of the page
 
June7
post May 22 2020, 10:24 PM
Post#2



Posts: 1,533
Joined: 25-January 16
From: The Great Land


I faced this issue once and never did find answer. Contributed to my decision to eliminate Excel component of database.


--------------------
Attachments Manager is below the edit post window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Go to the top of the page
 
tina t
post May 23 2020, 01:11 AM
Post#3



Posts: 6,690
Joined: 11-November 10
From: SoCal, USA


hmm, i wonder...do you by chance have code running in the same procedure - after the FollowHyperlink line - that does something like close a form, or set focus to a control, or anything else that might be manipulating an Access object...maybe something like that could bring the software "back to the front", though i'm only guessing.

hth
tina
This post has been edited by tina t: May 23 2020, 01:13 AM

--------------------
"the wheel never stops turning"
Go to the top of the page
 
June7
post May 23 2020, 01:19 AM
Post#4



Posts: 1,533
Joined: 25-January 16
From: The Great Land


Been a while since I dealt with this so I did some testing to open Excel. Included code to try opening form and setting focus to it after Excel opens. Form opens but focus remains on Excel and it stays in foreground.

Might find this of interest https://visualbasic.happycodings.com/applic...-vba/code5.html


This post has been edited by June7: May 23 2020, 01:26 AM

--------------------
Attachments Manager is below the edit post window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Go to the top of the page
 
jabm
post May 23 2020, 08:57 AM
Post#5



Posts: 78
Joined: 29-January 20
From: Londonderry, NH. USA


Hi Tina - I don't have anything but an end if and end sub after the Application.FollowHyperlink line -- Is there something I can add that would bring either a PDF Reader or a Photo viewer (some items might be scanned in as jpegs vs PDF)
(and the MsgBox statements are for my own debugging and will be removed later)

June - I will look at the link you provided a little later

Private Sub EmployeeChecklistDocumentFilePath_Click()
MsgBox "You clicked on the Employee Checklist Document File Path field"
' If the value of EmployeeChecklistDocumentFilePath is null then find get the full document path

If IsNull(Me.EmployeeChecklistDocumentFilePath.Value) = True Then
MsgBox "Employee Checklist Document File Path is empty"
Me.EmployeeChecklistDocumentFilePath.Value = FullDocFilePath("C:\")
Else
MsgBox "Employee Checklist Document File Path is *NOT* empty - value = '" & Me.EmployeeChecklistDocumentFilePath.Value & "'"
Application.FollowHyperlink Me.EmployeeChecklistDocumentFilePath.Value
End If
End Sub

Thanks

Julia
Go to the top of the page
 
theDBguy
post May 23 2020, 09:22 AM
Post#6


UA Moderator
Posts: 78,487
Joined: 19-June 07
From: SunnySandyEggo


Hi. Can't say from here either why the file/image is in the background, but you might try using the ShellExecute API to see if you can force it into the foreground. Just a thought...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
tina t
post May 23 2020, 09:44 AM
Post#7



Posts: 6,690
Joined: 11-November 10
From: SoCal, USA


hmm, okay. well, i routinely open Excel files, though not using FollowHyperlink, and they stay in front - i don't recall using anything to put/keep the Excel files in front, but i can check my code next week. as for other file types, i do use FollowHyperlink to open pdf files...man, i run that code so routinely, multiple times every workday, and i'm wracking my brain trying to recall if the pdf files stays to the front or if i move to it using alt+tab. i think it sticks to the front, but that's another thing i can check next week.

hth
tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
jabm
post May 23 2020, 04:10 PM
Post#8



Posts: 78
Joined: 29-January 20
From: Londonderry, NH. USA


Hmmm... Got a hint from another source and it might be because my form is a pop-up...
Need to investigate that..

Julia
Go to the top of the page
 
jabm
post May 25 2020, 01:27 PM
Post#9



Posts: 78
Joined: 29-January 20
From: Londonderry, NH. USA


Actually just tested that -- made a copy of my small database subset and changed the form to *NOT* be a pop-up -- the Adobe Acrobat Reader is *STILL* being put behind automatically. JPG files are on top - both with the form as a Pop-up and when not. It seems to have something to do with the interaction between Access and Adobe Acrobat Reader.....

The default Windows 10 photo viewer is staying on top of Access when the file to be opened is a jpg - but Adobe Acrobat Reader for the PDFs is not...

Any ideas?

Just 2 weeks ago I did have to reinstall everything as my computer crashed - didn't lose files/data, but had to reinstall just about everything and I am still trying to get my settings back to where I like them. Could this be a settings issue?

To TheDBGuy - I've never used the ShellExecute API and have only seen an occasional reference to it on other threads/pages, and therefore I have no idea where to start with this. Any resources for understanding how to use this?

To June7 -- I now have the opportunity to follow the link you shared - will explore that.

Thank you all!
Go to the top of the page
 
jabm
post May 25 2020, 04:52 PM
Post#10



Posts: 78
Joined: 29-January 20
From: Londonderry, NH. USA


Got it to work after more research -- I couldn't get the correct path for the Windows 10 default photo viewer - just using the Application.Followhyperlink unless file extention is PDF not sure why Application.Followhyperlink kept auto hiding Adobe Acrobat Reader but this works!


Using these Public Functions and this in my textbox click event
Public Function GetFileExtension(FullPath As String)
' as found at https://www.thespreadsheetguru.com/the-code...ile-path-string
GetFileExtension = Right(FullPath, Len(FullPath) - InStrRev(FullPath, "."))
End Function

Public Function OpenDoc(FullPath As String)
Dim FileExt As String
Dim FileOpenApp As String

FileExt = GetFileExtension(FullPath)
If FileExt = "pdf" Then
'need specific instructions for opening PDFs and keeping file on top of Access
' Shell command formatting found at
'https://stackoverflow.com/questions/55342136/vba-shell-command-with-variables-and-spaces
FileOpenApp = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"
Shell """" & FileOpenApp & """" & " " & """" & FullPath & """", vbNormalFocus
Else
'just let Windows handle the opening
Application.FollowHyperlink FullPath
End If
OpenDoc = (Err = 0)
End Function

Public Function FullDocFilePath(aStartFolder As String) As String
' As found at https://stackoverflow.com/questions/3546242...g-vba-in-access
' entry by cisco as answered on Feb 20 '16 at 9:12

On Error GoTo Err_FullDocFilePath

Dim fDialog As Office.FileDialog
Dim varfile As Variant
Dim strPath As String
Dim strFilter As String, strFileName As String
Dim Main_Dir As String, DefFolder As String

Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

With fDialog
.InitialView = msoFileDialogViewThumbnail
.AllowMultiSelect = False
.Title = "Please select document file"
.InitialFileName = aStartFolder
.InitialView = msoFileDialogViewThumbnail
.Filters.Clear
.Filters.Add "all files", "*.*"

' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.

If .Show = True Then
FullDocFilePath = .SelectedItems(1)
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With

Exit_FullDocFilePath:
Exit Function

Err_FullDocFilePath:
MsgBox Err.Description, vbCritical, "MyApp"
Resume Exit_FullDocFilePath
End Function


Private Sub EmployeeChecklistDocumentFilePath_Click()
' If the value of EmployeeChecklistDocumentFilePath is null then find get the full document path
If IsNull(Me.EmployeeChecklistDocumentFilePath.Value) = True Then
Me.EmployeeChecklistDocumentFilePath.Value = FullDocFilePath("C:\")
Else
Call OpenDoc(Me.EmployeeChecklistDocumentFilePath.Value)
End If
End Sub
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    12th July 2020 - 02:03 PM