Re: Files launched w/ Followhyperlink open but not visible



It appears that you got a useful answer on using Shell. My initial detail
look at that had led me to a more complicated solution, which I did not
think would be appropriate... but I did not try it.

What I did try was a simple test of Application.FollowHyperlink to see if I
could "force" the file to open in the background as you described, by
setting the active form from whose code it was executed to PopUp or Modal.
And it turned out that I could not... the application opened by
FollowHyperlink always opened in the foreground... Normal, PopUp or Modal.
Then when I closed that application's window, focus in each case returned to
the Access application that was opened behind it. I tried it on a .JPG
opened with Paint Shop Pro 9 and a Spread*** opened with Microsoft Excel
2003.

I created a simple, unbound form with two command buttons. In the General,
Declarations section of the Form's module, I defined

Dim strPathAndFile As String

Slightly modified from the API0001 code, was the click event:

Private Sub cmdBrowse_Click()
On Error GoTo Err_cmdBrowse_Click

Dim strFilter As String
Dim lngFlags As Long
' strFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda, *.mdb)",
_
"*.MDA;*.MDB")
' strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)",
"*.DBF")
' strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
strPathAndFile = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Hello! Open Me!")


MsgBox "You selected: " & strPathAndFile
' Since you passed in a variable for lngFlags,
' the function places the output flags value in the variable.
Debug.Print Hex(lngFlags)



Exit_cmdBrowse_Click:
Exit Sub

Err_cmdBrowse_Click:
MsgBox Err.Description
Resume Exit_cmdBrowse_Click

End Sub

And, in the other button's click event, the following to open the file by
hyperlinking (and by the way, I tried this with both True and False for the
New Window argument.

Private Sub cmdFollowHyperlink_Click()
On Error GoTo Err_cmdFollowHyperlink_Click

Application.FollowHyperlink strPathAndFile, , False, True

Exit_cmdFollowHyperlink_Click:
Exit Sub

Err_cmdFollowHyperlink_Click:
MsgBox Err.Description
Resume Exit_cmdFollowHyperlink_Click

End Sub

Summary: I could not reproduce what you describe, so I'm wondering what form
or application settings in the Access application might cause the file to
open behind it. My testing was done in Access 2003 (using 2002/2003 file
format).

Why don't you compare my code with yours and perhaps create a new Access
application -- nothing "fancy" or out of the ordinary, to see if it works
for you as it did before, or as it does for me.

Larry Linson
Microsoft Office Access MVP





"Ruben" <rubenfmunoz@xxxxxxxxx> wrote in message
news:57de549a-6d89-4450-9119-e488e29415b6@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On May 8, 11:26 am, "Larry Linson" <boun...@xxxxxxxxxxxxx> wrote:
You can use the code athttp://www.mvps.org/access/api/api0001.htmto open
the Windows Common Dialog to allow the user to choose a file, and then you
can use VBA code to use that file selection in the Shell function.

When you follow hyperlink, it opens an instance of the software registered
for the file-type... that is not part of your Application, nor in a
Control
in your application. You would have to determine some API that would make
it
the active window, or perhaps you could minimize the Access database you
are
running.

Larry Linson
Microsoft Office Access MVP

"Ruben" <rubenfmu...@xxxxxxxxx> wrote in message

news:d3c34892-136a-4fae-ba22-409949de6909@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On May 8, 2:24 am, kaisersose1995 <kaisersose1...@xxxxxxxxxxx> wrote:





On 8 May, 01:23, Ruben <rubenfmu...@xxxxxxxxx> wrote:

Hello,

I am using the "Application.FollowHyperlink strFilePath, , True" line
of code from within access forms to launch any file type I want (e.g.,
xls, doc, pdf, etc.). The files open up okay, but open up in the
background. How do I make them open in front where they are visible?
I have tried various things like "Appliction.Visible=True / False"
and "Screen.ActiveControl.Visible=True / False" but have not been able
to figure it out.

Anyones help with this would be very much appreciated.

Regards,

Ruben Munoz

Instead of using FollowHyperlink have you considered using the Shell
command?
e.g
Shell("C:\MSOffice\OFFICE11\WINWORD.EXE C:\Somedir\..\..
\somefile.doc", vbMaximizedFocus)

this will open the word doc somefile, maximised on top of all other
windows.

Regards

Richard

Thanks for your response. Yes I have considered the Shell command.
And although the Shell command works, I can't figure out how to make
it work within my application.

I am using Access 2000. What this part of my application does is that
it enables users to click on a hyperlink text field within a form in
order to "attach" external documents such as xls, doc, pdf, etc., to
the form. This launches the Open File Dialog from which they can
select the file they want to "attach". Once a selection has been
made, the file path to their document is captured to that text field
as a hyperlink that launches their file or document the next time a
user clicks on it.

Unless there's a way to assign the "attached" file path within the
Shell command to a string or variable, I don't know if the Shell
command could be made to work in this case. As it stands now,
"Application.FollowHyperlink strFilePath, , True" is the only other
line of code I found that works to the extent of opening up external
files or applications, I just can't get these to open up on top.

-Ruben- Hide quoted text -

- Show quoted text -

Larry,

The code referenced in your response is just what I used for the
Windows Common Dialog. What I don't know is how exactly to use or
incorporate this into the Shell function. Any specific ideas or
examples on what this would look like would be helpful and most
certainly appreciated.

Ruben


.