VBA MS Access 2007 超链接插入按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7383376/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 13:59:54  来源:igfitidea点击:

VBA MS Access 2007 hyperlink insert button

vbahyperlinkinsertms-access-2007

提问by Denbigh

I have a button which inserts a hyperlink into a new record. The field's IsHyperlink property is set to "yes", so I get the hand, but clicking on the inserted path does not go anywhere. I believe the button is updating the record with the path of the file as "text to display" rather than "address."

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

   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

I know that putting the following code in at the ** works in Excel, I am after something like it which will work in Access!

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

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

回答by HansUp

Try this if you want the file path as both the hyperlink address and display text.

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

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

If you want the address with only the file name (without the path) as the display text, try this:

如果您希望只有文件名(没有路径)的地址作为显示文本,请尝试以下操作:

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

See HyperlinkPart Methodfor more background information. You might even prefer to manipulate your hyperlink field data using HyperlinkPart.

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