2011-09-12 51 views
1

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

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" 

回答

2

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

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

如果你想只用文件名作为显示文本的地址(不带路径),试试这个:

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

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

+0

它的工作原理!谢谢@HansUp – Denbigh