VBA MS Access 2007 超链接插入按钮

发布于 2024-12-03 23:32:53 字数 1099 浏览 5 评论 0原文

我有一个按钮,可以将超链接插入新记录。该字段的 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"

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."

   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!

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北恋 2024-12-10 23:32:54

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

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

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

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

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

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 Method for more background information. You might even prefer to manipulate your hyperlink field data using HyperlinkPart.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文