Hey, I am using Access 2010 on a cloud network.
I am having trouble with my hyperlink field to a pdf document located on a cloud drive. The user sets the hyperlink themselves by clicking btnGetLink and searching for the file. When the user selects the file, the hyperlink is put in the txtLink text box which is bound to my table. The hyperlink in the text box works fine when copied into windows explorer (when I go to edit hyperlink and select the hyperlink, not the actual text in the text box) but clicking on the hyperlink itself yields an error message "An unexpected error has occurred". Here is a sample hyperlink address: "K:\Common\User\David\Signed Leases\Lease528.pdf" The K: drive is the cloud network drive which I am also running access off of.
This is the code:
If anyone could provide some assistance as to why clicking the hyperlink yields an error message, that would be great!
Thanks
**I did not write this code. It is from http://bytes.com/topic/access/insigh...hyperlink-form
I am having trouble with my hyperlink field to a pdf document located on a cloud drive. The user sets the hyperlink themselves by clicking btnGetLink and searching for the file. When the user selects the file, the hyperlink is put in the txtLink text box which is bound to my table. The hyperlink in the text box works fine when copied into windows explorer (when I go to edit hyperlink and select the hyperlink, not the actual text in the text box) but clicking on the hyperlink itself yields an error message "An unexpected error has occurred". Here is a sample hyperlink address: "K:\Common\User\David\Signed Leases\Lease528.pdf" The K: drive is the cloud network drive which I am also running access off of.
This is the code:
Code:
Private Sub btnGetLink_Click()
Dim strButtonCaption As String, strDialogTitle As String
Dim strHyperlinkFile As String, strSelectedFile As String
'Define your own Captions if necessary
strButtonCaption = "Save Hyperlink"
strDialogTitle = "Select File to Create Hyperlink to"
With Application.FileDialog(msoFileDialogFilePicker)
With .Filters
.Clear
.Add "All Files", "*.*" 'Allow ALL File types
End With
'The Show Method returns True if 1 or more files are selected
.AllowMultiSelect = False 'Critical Line
.FilterIndex = 1 'Database files
.ButtonName = strButtonCaption
.InitialFileName = "K:\Common\User\David\Signed Leases"
.InitialView = msoFileDialogViewDetails 'Detailed View
.Title = strDialogTitle
If .Show Then
For Each varItem In .SelectedItems 'There will only be 1
'Display Text + # + Address of Hyperlink (Display Text#Hyperlink Address)
strSelectedFile = varItem
strHyperlinkFile = fGetBaseFileName(strSelectedFile) & "#" & strSelectedFile
Me![txtLink] = strHyperlinkFile
Next varItem
End If
End With
End Sub
Public Function fGetBaseFileName(strFilePath As String) As String
'This Function accepts the Absolute Path to a File and returns the Base File
'Name (File Name without the Extension)
'Make absolutely sure that it is a valid Path/Filename
If Dir$(strFilePath) = "" Then Exit Function
Dim strFileName As String
Dim strBaseFileName As String
strFileName = Right$(strFilePath, Len(strFilePath) - InStrRev(strFilePath, "\"))
strBaseFileName = Left$(strFileName, InStr(strFileName, ".") - 1)
fGetBaseFileName = strBaseFileName
End Function
If anyone could provide some assistance as to why clicking the hyperlink yields an error message, that would be great!
Thanks
**I did not write this code. It is from http://bytes.com/topic/access/insigh...hyperlink-form