FollowHyperlink error when referred to from a different control (1 Viewer)

nortonm

Registered User.
Local time
Today, 00:06
Joined
Feb 11, 2016
Messages
50
Hi -
I am creating a database of student 'Placement Incidents', and one request was that lecturers are able to add supporting attachments to the main PlacementIncident record.

I have FileCopy working to copy documents from the PC documents folder to the database’s attachment folder. It then adds the attachment URL to my database’s ‘Attachment’ table (full UNC, not a lettered drive). The data type in the attachment table (for the UNC) I’ve set as ‘Hyperlink’.

I have the Attachment table in a subform on a main record form (the main record can hold multiple attachments), so the various attachments can be viewed.

The problem is I don’t want to show the full long UNC in the subform, I want to hide that field, and have the Application.FollowHyperlink run from the attachment’s short name field: “FileName”, by using code :

“Application.FollowHyperlink Me.Inc_Att_Link”, where ‘Inc_Att_Link’ is the working clickable field in the table.

However, I get the debug error “‘Run-time error ‘490’. Cannot open the specified file.” when clicking the FileName in the form, but if I make the UNC field (Inc_Att_Link) visible in the subform and click that, it opens the attachment fine.

Have any of you come across this before - do you know why I can’t get the FileName on-click event to open the attachment UNC written in the field “Inc_Att_Link”?
 
I do not use followhyperlink - you have the associated files in a dedicated folder, so the path is defined. You simply need to open the file using the link. Creation of the record and possible edit of the display name and to make the display name work like a hyperlink. Something like as shown here:

https://www.access-programmers.co.u...the-document-not-the-path.333798/post-1958895

On double click of the displayed name:
Call ExecuteFile(Me.txtDocLink, "Open")

The executeFile is a module:
Code:
Public Sub ExecuteFile(sFileName As String, sAction As String)
    Dim vReturn               As Long
    'sAction can be either "Open" or "Print".

    If ShellExecute(Access.hWndAccessApp, sAction, sFileName, vbNullString, "", SW_SHOWNORMAL) < 33 Then
        DoCmd.Beep
        MsgBox "File not found."
    End If
End Sub

With the declarations :

Code:
Private Const sModName = "modExternalFiles" 'Application.VBE.ActiveCodePane.CodeModule

'Source: http://www.pacificdb.com.au/MVP/Code/ExeFile.htm
Public Const SW_HIDE = 0
Public Const SW_MINIMIZE = 6
Public Const SW_RESTORE = 9
Public Const SW_SHOW = 5
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMINNOACTIVE = 7
Public Const SW_SHOWNA = 8
Public Const SW_SHOWNOACTIVATE = 4
Public Const SW_SHOWNORMAL = 1

#If Win64 Then

Public Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
                                     (ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, _
                                      ByVal lpParameters As String, ByVal lpDirectory As String, _
                                      ByVal nShowCmd As Long) As LongPtr
                                    
#Else
Public Declare  Function ShellExecute 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
#End If
 
try this short code:
Code:
FollowHyperlink Me.Inc_Att_Link.Hyperlink.Address
 

Users who are viewing this thread

Back
Top Bottom