HyperlinkPart Method Example

The following example uses all four of the part argument constants to display information returned by the HyperlinkPart method for each record in a table containing a Hyperlink field. To try this example, paste the DisplayHyperlinkParts procedure into the Declarations section of a module. You can call the DisplayHyperlinkParts procedure from the Debug window, passing to it the name of a table containing hyperlinks and the name of the field containing Hyperlink data. For example:

DisplayHyperlinkParts "MyHyperlinkTableName", "MyHyperlinkFieldName"

Sub DisplayHyperlinkParts(strTable As String, strField As String)
    Dim rst As New ADODB.Recordset
    Dim strMsg As String

        
    rst.Open(strTable,currentproject.connection,_
        adOpenForwardOnly, adLockReadOnly)

    While Not rst.EOF        ' For each record in table.
        strMsg = "DisplayValue = " _
            & HyperlinkPart(rst(strField), acDisplayedValue) _
            & vbCrLf & "DisplayText = " _
            & HyperlinkPart(rst(strField), acDisplayText) _
            & vbCrLf & "Address = " _
            & HyperlinkPart(rst(strField), acAddress) _
            & vbCrLf & "SubAddress = " _
            & HyperlinkPart(rst(strField), acSubAddress) _
            & vbCrLf & "ScreenTip = " _
            & HyperlinkPart(rst(strField), acScreenTip) _
            & vbCrLf & "Full Address = " _
            & HyperlinkPart(rst(strField), acFullAddress)
        ' Show parts returned by HyperlinkPart function.
        MsgBox strMsg
        rst.MoveNext
    Wend
End Sub

When you use the HyperlinkPart method in a query, the part argument is required. For example, the following SQL statement uses the HyperlinkPart method to return information about data stored as a Hyperlink data type in the URL field of the Links table:

SELECT Links.URL, HyperlinkPart([URL],0)
AS Display, HyperlinkPart([URL],1)
AS Name, HyperlinkPart([URL],2)
AS Addr, HyperlinkPart([URL],3)
AS SubAddr, HyperlinkPart([URL],4)
AS ScreenTip
FROM Links;