Access DB - Save file location (full) link/path in one field and file name in other field (both or either should be clickable to open the file)

只谈情不闲聊 提交于 2020-08-20 04:31:23

问题


This is my first post and I am new to MS Access with no coding experience. I have a Access Database with a table call Attachments with field as "Saved Path" & "File Name". Both are Hyperlink data type.

Since there is limit of 2GB under MS Access attachments option, I would like to save a link to the file saved outside of MS Access.

What I am looking for is, when a user click on Saved Path it opens a windows dialogue box and user select the file (already created and saved under a network path) and this link/path including file name gets saved under this column. So when required they can refer back to that record and just click on the like to open that file directly from there. And under File Name field the name of the file is copied and saved.

Private Sub Saved_Path_Click()

    Dim f As Object
    Dim strFullpath As String
    Dim strFolder As String
    Dim strFile As String
    Dim intPos As Integer
    Dim varItem As Variant
    
    Set f = Application.FileDialog(3)
    f.AllowMultiSelect = False
    strFullpath = BrowseFile
    
    If f.Show Then
        
        intPos = InStrRev(strFullpath, "\")
               
        
        Me.Saved_Path = "#" & f.SelectedItems(1) & "#"
        Application.FollowHyperlink Me.Saved_Path
   
    End If
    Set f = Nothing    
 
End Sub

回答1:


That code is not saving hyperlink string to Hyperlink type field. Access Hyperlink field data is a string composed of 3 parts separated by # character.
display text # file path\name # any reference within the file

Could have only one field (Hyperlink or Text) with full path\filename and use code to split the string when you want path or filename part.

If you use a Hyperlink type field, save full file path name formatted as a hyperlink string so it is a clickable hyperlink to open file.
Me.fieldname = "#" & f.SelectedItems(1) & "#"
Can extract path part from f.SelectedItems(1) and save to its own Hyperlink field if you want.

If you save path parts, without # characters, to separate normal text fields, options:

VBA FollowHyperlink intrinsic function in Click event procedure to open file

or

calculate a clickable hyperlink string in textbox ControlSource (no VBA).
="Click to open folder#" & [Saved_Path] & "#"
="Click to Open file#" & [Saved_Path] & "\" & [File_Name] & "#"

Set textbox IsHyperlink property to Yes so text looks like a link.



来源:https://stackoverflow.com/questions/63246079/access-db-save-file-location-full-link-path-in-one-field-and-file-name-in-ot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!