浏览文件按钮在Access中另存为超链接

时间:2016-03-03 13:37:00

标签: vba ms-access access-vba

在表单中,我有多个附件字段,我插入超链接(右键单击编辑超链接)。 所有文件都位于网络目录

\\ap1\tools\db...

我想要一个带有点击事件的按钮,打开一个"浏览文件"从

开始

\\ap1\tools\db...

并将所选文件作为超链接放入相应的字段中。

我认为vba是最好的解决方案,但我不知道从哪里开始。

1 个答案:

答案 0 :(得分:0)

经过一番研究后,我相信我已经解决了自己的问题

 Private Sub btnAttachment1_Click()

   Const msoFileDialogFilePicker As Long = 3

   Dim fd As Object
'Create a FileDialog object as a File Picker dialog box.
   Set fd = Application.FileDialog(msoFileDialogFilePicker)
'Use a With...End With block to reference the FileDialog object.
   With fd
'Set the initial path to the D:\Documents\ folder.
   .InitialFileName = "\\ap1\tools\db\"
   .Title = "Select Attachment"
'Use the Show method to display the File Picker dialog box and return the user's action.
'If the user presses the action button...
   If .Show = -1 Then
'   DoCmd.GoToRecord , "", acNewRec
   Me![Attachment1] = "#" & .SelectedItems(1) & "#"

'  **

'If the user presses Cancel...
   Else
   End If
 End With

'Set the object variable to Nothing.
   Set fd = Nothing


End Sub