【问题标题】:VBA MS Access 2007 hyperlink insert buttonVBA MS Access 2007 超链接插入按钮
【发布时间】:2011-09-12 22:36:25
【问题描述】:

我有一个将超链接插入新记录的按钮。该字段的 IsHyperlink 属性设置为“yes”,所以我得到了帮助,但是单击插入的路径不会去任何地方。我相信该按钮正在使用文件路径作为“要显示的文本”而不​​是“地址”来更新记录。

   Private Sub MSDS_btn_Click()
   Dim fd As Office.FileDialog
'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 = "D:\Documents\"
   .Title = "Select MSDS"
'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![Link MSDS] = .SelectedItems(1)

  **

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

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

我知道将以下代码放在 ** 中可以在 Excel 中使用,我正在寻找可以在 Access 中使用的类似代码!

 ActiveSheet.Hyperlinks.Add Anchor:=Cells(ActiveCell.row, Range("LinkCol").Column), Address:=.SelectedItems(1), TextToDisplay:="MSDS"

【问题讨论】:

    标签: vba hyperlink insert ms-access-2007


    【解决方案1】:

    如果您希望文件路径同时作为超链接地址和显示文本,请尝试此操作。

    Me![Link MSDS] = "#" & .SelectedItems(1) & "#"
    

    如果你想要只包含文件名(没有路径)的地址作为显示文本,试试这个:

    Me![Link MSDS] = Dir(.SelectedItems(1)) & "#" & .SelectedItems(1) & "#"
    

    有关更多背景信息,请参阅HyperlinkPart Method。您甚至可能更喜欢使用 HyperlinkPart 来操作超链接字段数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 2018-06-24
      • 2017-01-16
      • 2013-04-18
      相关资源
      最近更新 更多