D
Davy
I have been using Dev Ashish's code which uses ShellExcute (see below) to
open the registered jpg program which in my case is IrfanView. But each
time it runs it opens a new instance of IrfanView. This is inconvenient
since I am viewing more than 200 images by clicking on a thumbnail in an
Access 2000 database. Can anybody guide a VBA novice like myself on how to
change this code to open a file in the current instance of InfranView? It
needs to work both in Windows NT and 2000. IrfanView has a switch "/one"
which forces a single instance. Would it be sufficient to add the switch to
the file associations in Windows?
many thanks
David
' This code was originally written by Dev Ashish.
' 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 Ashish
''***************Usage Examples***********************
'Open a folder: fHandleFile("C:\TEMP\",WIN_NORMAL)
'Call Email app: fHandleFile("mailto:[email protected]",WIN_NORMAL)
'Open URL: fHandleFile("http://home.att.net/~dashish", WIN_NORMAL)
'Handle Unknown extensions (call Open With Dialog):
' fHandleFile("C:\TEMP\TestThis",Win_Normal)
'Start Access instance:
' 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
'First try ShellExecute
lRet = apiShellExecute(hWndAccessApp, vbNullString, _
stFile, vbNullString, vbNullString, lShowHow)
If lRet > ERROR_SUCCESS Then
stRet = vbNullString
lRet = -1
Else
Select Case lRet
Case ERROR_NO_ASSOC:
'Try the OpenWith dialog
varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL "
_
& stFile, WIN_NORMAL)
lRet = (varTaskID <> 0)
Case ERROR_OUT_OF_MEM:
stRet = "Error: Out of Memory/Resources. Couldn't Execute!"
Case ERROR_FILE_NOT_FOUND:
stRet = "Error: File not found. Couldn't Execute!"
Case ERROR_PATH_NOT_FOUND:
stRet = "Error: Path not found. Couldn't Execute!"
Case ERROR_BAD_FORMAT:
stRet = "Error: Bad File Format. Couldn't Execute!"
Case Else:
End Select
End If
fHandleFile = lRet & _
IIf(stRet = "", vbNullString, ", " & stRet)
End Function
open the registered jpg program which in my case is IrfanView. But each
time it runs it opens a new instance of IrfanView. This is inconvenient
since I am viewing more than 200 images by clicking on a thumbnail in an
Access 2000 database. Can anybody guide a VBA novice like myself on how to
change this code to open a file in the current instance of InfranView? It
needs to work both in Windows NT and 2000. IrfanView has a switch "/one"
which forces a single instance. Would it be sufficient to add the switch to
the file associations in Windows?
many thanks
David
' This code was originally written by Dev Ashish.
' 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 Ashish
''***************Usage Examples***********************
'Open a folder: fHandleFile("C:\TEMP\",WIN_NORMAL)
'Call Email app: fHandleFile("mailto:[email protected]",WIN_NORMAL)
'Open URL: fHandleFile("http://home.att.net/~dashish", WIN_NORMAL)
'Handle Unknown extensions (call Open With Dialog):
' fHandleFile("C:\TEMP\TestThis",Win_Normal)
'Start Access instance:
' 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
'First try ShellExecute
lRet = apiShellExecute(hWndAccessApp, vbNullString, _
stFile, vbNullString, vbNullString, lShowHow)
If lRet > ERROR_SUCCESS Then
stRet = vbNullString
lRet = -1
Else
Select Case lRet
Case ERROR_NO_ASSOC:
'Try the OpenWith dialog
varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL "
_
& stFile, WIN_NORMAL)
lRet = (varTaskID <> 0)
Case ERROR_OUT_OF_MEM:
stRet = "Error: Out of Memory/Resources. Couldn't Execute!"
Case ERROR_FILE_NOT_FOUND:
stRet = "Error: File not found. Couldn't Execute!"
Case ERROR_PATH_NOT_FOUND:
stRet = "Error: Path not found. Couldn't Execute!"
Case ERROR_BAD_FORMAT:
stRet = "Error: Bad File Format. Couldn't Execute!"
Case Else:
End Select
End If
fHandleFile = lRet & _
IIf(stRet = "", vbNullString, ", " & stRet)
End Function