I have searched experts exchange and found the following solution:
Add the module below:
Private Const ERROR_SUCCESS = 32&
Private Const ERROR_NO_ASSOC = 31&
Private Const ERROR_OUT_OF_MEM = 0&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&
Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
Declare Function ShellExecuteAPI Lib "Shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Declare Function FindExecutable Lib "Shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
Public Function BrowseURL(ByVal sURL As String)
Dim lRet As Long, vTaskID As Variant
Dim sRet As String
Dim hFile As Long
Dim sResult As String
Dim iPos As Integer
Dim sExplorerPath As String
'First try ShellExecute
lRet = ShellExecuteAPI(hWndAccess
App, vbNullString, sExplorerPath, sURL, vbNullString, 1)
If lRet > ERROR_SUCCESS Then
sRet = vbNullString
lRet = -1
Else
Select Case lRet
Case ERROR_NO_ASSOC:
'Try the OpenWith dialog
vTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
& sExplorerPath, WIN_NORMAL)
lRet = (vTaskID <> 0)
Case ERROR_OUT_OF_MEM:
sRet = "Error: Out of Memory/Resources. Couldn't Execute!"
Case ERROR_FILE_NOT_FOUND:
sRet = "Error: File not found. Couldn't Execute!"
Case ERROR_PATH_NOT_FOUND:
sRet = "Error: Path not found. Couldn't Execute!"
Case ERROR_BAD_FORMAT:
sRet = "Error: Bad File Format. Couldn't Execute!"
Case Else:
End Select
If sRet <> vbNullString Then MsgBox sRet
End If
BrowseURL = lRet & _
IIf(sRet = "", vbNullString, ", " & sRet)
End Function
**************************
**********
**********
*****
Then
add this under the link onclick event on the form.
Private Sub LinkLocation_Click()
'MsgBox Me.LinkLocation.Text & "#" & Me.LinkLocation.Text
browseFiles.BrowseURL Me.LinkLocation.Text
End Sub
**************************
**********
**********
***
It works great but.......
I get a explorer window that goes to the folder that holds the file, it does not try to open the file I have tested with all file types that I will be linking .doc, .pdf, .zip, .exe and none of them work.
Any help on getting the missing link working would be great!!!!
Thanks,
Josh
Start Free Trial