2011-09-12 102 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