Link to home
Start Free TrialLog in
Avatar of WS
WSFlag for United Arab Emirates

asked on

MS Access - Hyperlink open message disable

Hi,

I have a subform that have a hyperlink field which open the document to which that Source is link. When clicking on Link path it display Message which i shown in attach image. I have tried using VBA Code as "Docmd.SetWarning False",Also the location is put as trusted Location and look for other stuff also on google but no luck. Can any one help me in this like how to stop showing this message everytime a link is open.

Message: "Some file contains viruses or may be harmful to your computer.  It is important to be certain that this file is from trustworthy source. Would you like to open this file."

Thanks in advance.
hyperlink_error.png
Avatar of Anders Ebro (Microsoft MVP)
Anders Ebro (Microsoft MVP)
Flag of Denmark image

You can't disable the prompt, but you can open your file in a different way. Try looking at this article:
http://access.mvps.org/access/api/api0018.htm
You can also use the Application.FollowHyperlink method.  I don't generally use the hyperlink data type in my applications.  Instead, I store the hyperlink in a text field, and include a button next to the text field with a Click event:
Private Sub btn_Launch_Click

    Application.FollowHyperlink me.txtHyperlink

End Sub

Open in new window

Avatar of WS

ASKER

@Dale, actually i have also use text data type for this field in table and then in the subform i have add a code "On-Click" so when the user click on the Link path it open that pdf or other document from that location.Below is the code i have use in On Click event :

...
Private Sub Link_path_Click()
On Error GoTo Link_path_Click_Err

Dim path As String
path = "\\xxx.xx.xx.xx\Data" & Me.Link_path
DoCmd.SetWarnings False
Application.FollowHyperlink path
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdAppMinimize 'Minimize the MS Access Application
Link_path_Click_Exit:
    Exit Sub
    
Link_path_Click_Err:
    MsgBox "Can't open file,Invalid Path"
    Resume Link_path_Click_Exit
End Sub

Open in new window

...
Also for information i am using relative path.
and you are still getting the warning?  I'm using 2007 and that warning does not popup.

If you are still getting the warning, use the ShellExecute technique provided by Anders.
Avatar of WS

ASKER

@Dale , can you let me know where i should put your line of code in my code the one mention above in my last comment as i am already using "Application.FollowHyperlink path" as you can see in my code so how i should change that or something?
Avatar of WS

ASKER

@Anders, can you explain a bit more about that code like how to open with other technique? how can i incorporate my code with the other one?
I haven't used that myself recently, but I imagine it is as simple as:
Private Sub Link_path_Click()
On Error GoTo Link_path_Click_Err

Dim path As String
path = "\\xxx.xx.xx.xx\Data" & Me.Link_path
fHandleFile path
DoCmd.RunCommand acCmdAppMinimize 'Minimize the MS Access Application
Link_path_Click_Exit:
    Exit Sub
    
Link_path_Click_Err:
    MsgBox "Can't open file,Invalid Path"
    Resume Link_path_Click_Exit
End Sub

Open in new window

Avatar of WS

ASKER

it gives compile error "Argument not optional".

'***Error Codes***
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&

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

Private Sub Link_path_Click()
On Error GoTo Link_path_Click_Err

Dim path As String
path = "\\xxx.xx.xx.xx\Data" & Me.Link_path
fHandleFile path
DoCmd.RunCommand acCmdAppMinimize 'Minimize the MS Access Application
Link_path_Click_Exit:
    Exit Sub
    
Link_path_Click_Err:
    MsgBox "Can't open file,Invalid Path"
    Resume Link_path_Click_Exit
End Sub

Open in new window

Private Sub Link_path_Click()
On Error GoTo Link_path_Click_Err

Dim path As String
path = "\\xxx.xx.xx.xx\Data" & Me.Link_path
fHandleFile path, WIN_NORMAL 
DoCmd.RunCommand acCmdAppMinimize 'Minimize the MS Access Application
Link_path_Click_Exit:
    Exit Sub
    
Link_path_Click_Err:
    MsgBox "Can't open file,Invalid Path"
    Resume Link_path_Click_Exit
End Sub

Open in new window

Avatar of WS

ASKER

it's giving error for these line of code, when i copy this in my code it turn this code to red, any idea why?

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

'***App Window Constants***
Public Const WIN_NORMAL = 1         'Open Normal
Public Const WIN_MAX = 3            'Open Maximized
Public Const WIN_MIN = 2            'Open Minimized

Open in new window

If I recall correctly, declarations must be at the top of the module code.
Avatar of WS

ASKER

yeah exactly ,on the top before on click event , still it's giving red , "by copy in my code" i mean like in my application.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.