On May 8, 1:21=A0pm, "paii, Ron" <n...@[EMAIL PROTECTED]
> wrote:
> "Ruben" <rubenfmu...@[EMAIL PROTECTED]
> wrote in message
>
>
news:877e8375-e061-44fd-8849-90bb86bd759e@[EMAIL PROTECTED]
>
> > 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.). =A0The files open up okay, but open up in the
> > background. =A0How do I make them open in front where they are
visible?
> > I have tried various things like =A0"Appliction.Visible=3DTrue /
False"
> > and "Screen.ActiveControl.Visible=3DTrue / False" but have not been
able=
> > to figure it out.
>
> > Anyones help with this would be very much appreciated.
>
> > Regards,
>
> > Ruben Munoz
>
> I have been using the following code to open any type of do***ent with
an
> associated program
>
> '************ Code Start **********
> ' This code was originally written by Dev A****sh.
> ' It is not to be altered or distributed,
> ' except as part of an application.
> ' You are free to use it in any application,
> ' provided the copyright notice is left unchanged.
> '
> ' Code Courtesy of
> ' Dev A****sh
> '
> Private Declare Function apiShellExecute Lib "shell32.dll" _
> =A0 =A0 Alias "ShellExecuteA" _
> =A0 =A0 (ByVal hwnd As Long, _
> =A0 =A0 ByVal lpOperation As String, _
> =A0 =A0 ByVal lpFile As String, _
> =A0 =A0 ByVal lpParameters As String, _
> =A0 =A0 ByVal lpDirectory As String, _
> =A0 =A0 ByVal nShowCmd As Long) _
> =A0 =A0 As Long
>
> '***App Window Constants***
> Public Const WIN_NORMAL =3D 1 =A0 =A0 =A0 =A0 'Open Normal
> Public Const WIN_MAX =3D 3 =A0 =A0 =A0 =A0 =A0 =A0'Open Maximized
> Public Const WIN_MIN =3D 2 =A0 =A0 =A0 =A0 =A0 =A0'Open Minimized
>
> '***Error Codes***
> Private Const ERROR_SUCCESS =3D 32&
> Private Const ERROR_NO_ASSOC =3D 31&
> Private Const ERROR_OUT_OF_MEM =3D 0&
> Private Const ERROR_FILE_NOT_FOUND =3D 2&
> Private Const ERROR_PATH_NOT_FOUND =3D 3&
> Private Const ERROR_BAD_FORMAT =3D 11&
>
> '***************Usage Examples***********************
> 'Open a folder: =A0 =A0 ?fHandleFile("C:\TEMP\",WIN_NORMAL)
> 'Call Email app: =A0
=A0?fHandleFile("mailto:das...@[EMAIL PROTECTED]
",WIN_NORMA=
L)
> 'Open URL: =A0 =A0 =A0 =A0
=A0?fHandleFile("http://home.att.net/~da****sh",=
WIN_NORMAL)
> 'Handle Unknown extensions (call Open With Dialog):
> ' =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
?fHandleFile("C:\TEMP\TestThis",Win_=
Normal)
> 'Start Access instance:
> ' =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
?fHandleFile("I:\mdbs\CodeNStuff.mdb=
", Win_NORMAL)
> '****************************************************
>
> Function fHandleFile(stFile As String, lShowHow As Long)
> Dim lRet As Long, varTaskID As Variant
> Dim stRet As String
> =A0 =A0 'First try ShellExecute
> =A0 =A0 lRet =3D apiShellExecute(hWndAccessApp, vbNullString, _
> =A0 =A0 =A0 =A0 =A0 =A0 stFile, vbNullString, vbNullString, lShowHow)
>
> =A0 =A0 If lRet > ERROR_SUCCESS Then
> =A0 =A0 =A0 =A0 stRet =3D vbNullString
> =A0 =A0 =A0 =A0 lRet =3D -1
> =A0 =A0 Else
> =A0 =A0 =A0 =A0 Select Case lRet
> =A0 =A0 =A0 =A0 =A0 =A0 Case ERROR_NO_ASSOC:
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 'Try the OpenWith dialog
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 varTaskID =3D Shell("rundll32.exe
shell32.=
dll,OpenAs_RunDLL "
> _
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 & stFile, WIN_NORMAL)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 lRet =3D (varTaskID <> 0)
> =A0 =A0 =A0 =A0 =A0 =A0 Case ERROR_OUT_OF_MEM:
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 stRet =3D "Error: Out of
Memory/Resources.=
Couldn't Execute!"
> =A0 =A0 =A0 =A0 =A0 =A0 Case ERROR_FILE_NOT_FOUND:
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 stRet =3D "Error: File not found.
=A0Could=
n't Execute!"
> =A0 =A0 =A0 =A0 =A0 =A0 Case ERROR_PATH_NOT_FOUND:
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 stRet =3D "Error: Path not found.
Couldn't=
Execute!"
> =A0 =A0 =A0 =A0 =A0 =A0 Case ERROR_BAD_FORMAT:
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 stRet =3D "Error: =A0Bad File Format.
Coul=
dn't Execute!"
> =A0 =A0 =A0 =A0 =A0 =A0 Case Else:
> =A0 =A0 =A0 =A0 End Select
> =A0 =A0 End If
> =A0 =A0 fHandleFile =3D lRet & _
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 IIf(stRet =3D "", vbNullString, ", " &
stR=
et)
> End Function
> '************ Code End **********
Ron,
Thanks very much for the sample code provided. The ShellExecute part
of the code work great! Is there any way to redirect the focus to
access upon closing the external file just launched? Otherwise, I can
certainly work with this.
Ruben


|