Clicking on hyperlink in the report

aman

Registered User.
Local time
Yesterday, 19:11
Joined
Oct 16, 2008
Messages
1,251
Hi Guys

Please see attached the screenshot. This is a report in access. What I want to do is to put some click event on the hyperlink in the Filepath so that will open up that file on the screen. Is it possible?

Any help will be much appreciated.

Thanks
 

Attachments

Yes it can be done but only if the report is opened in report view to allow user interaction.
Normally you'd do it from a form

DON'T USE THE HYPERLINK section in the property window

Instead, one way is to add code like this to either a label or textbox click event

Code:
Private Sub Label2_Click()
    Application.FollowHyperlink "C:\Windows\Notepad.exe"
End Sub

Private Sub Text0_Click()
    Application.FollowHyperlink "C:\Windows\Notepad.exe"
End Sub

Obviously replace the path with whatever file you want
You will get a warning about opening files from a trustworthy source using the above method

There are better ways which avoid that
For example using Windows Shell
Add this code to a standard module

Code:
Option Compare Database
Option Explicit

'Code Courtesy of Dev Ashish

Private Declare Function apiShellExecute 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

Public Sub ShellEx(ByVal Path As String, Optional ByVal Parameters As String, Optional ByVal HideWindow As Boolean)

On Error GoTo Err_Handler

    If Dir(Path) > "" Then
        apiShellExecute 0, "open", Path, Parameters, "", IIf(HideWindow, 0, 1)
    Else
        MsgBox "Can't find specified file"
    End If
    
Exit_Handler:
    Exit Sub
    
Err_Handler:
    MsgBox "Error " & Err.Number & " in ShellEx procedure : " & Err.Description, vbOKOnly + vbCritical
    Resume Exit_Handler

End Sub

Then write code similar to this in the click event for your report control
Code:
ShellEx "c:\windows\write.exe", , 0

There are other ways as well...
 

Users who are viewing this thread

Back
Top Bottom