浏览到文件位置并添加指向记录集的超链接

时间:2015-03-16 23:27:44

标签: ms-access ms-access-2007

我找到了一些代码,允许我浏览到文件位置,选择它,然后将文件路径字符串添加到表单上的文本框中。我想要做的是将文件路径字符串添加到我的数据库中的表。

有人可以告诉我该怎么做吗?提前谢谢!

Dim fdg As Object
Dim vrtSelectedItem As Variant
Dim strSelectedFile As String

Set fdg = Application.FileDialog(3)
'Set fdg = Application.FileDialog(msoFileDialogFilePicker)

With fdg
    .AllowMultiSelect = False
    '.InitialView = msoFileDialogViewDetails
        If .Show = -1 Then
            For Each vrtSelectedItem In .SelectedItems 'only be 1
                    strSelectedFile = vrtSelectedItem
                Next vrtSelectedItem
            Me![txtSelectedFile] = strSelectedFile
         Else 'The user pressed Cancel.
    End If
End With

Set fdg = Nothing

1 个答案:

答案 0 :(得分:0)

感谢您的回复,保罗。我在原始问题中遗漏了一个重要的细节。需要将文件路径添加到连续子表单中,因为每个记录可能包含多个需要链接的文件。我终于弄明白了。我使用的代码发布在下面:

Dim fdg As Object
Dim vrtSelectedItem As Variant
Dim strSelectedFile As String

Set fdg = Application.FileDialog(3)
'Set fdg = Application.FileDialog(msoFileDialogFilePicker)

With fdg
    .AllowMultiSelect = False
        If .Show = -1 Then
            For Each vrtSelectedItem In .SelectedItems 'only be 1
                    strSelectedFile = vrtSelectedItem
                Next vrtSelectedItem
                With Me.Child57
                .Form.[IMR_HYPRLNK].SetFocus
                    RunCommand acCmdRecordsGoToNew
                Me.Child57.Form.[IMR_HYPRLNK] = strSelectedFile
            End With
        Else 'The user pressed Cancel.
    End If
End With

Set fdg = Nothing