3

I have a form in Access 2016 with a textbox in which I need to have multiple, semi-colon delimited hyperlinks (which will be dynamically created). What I've decided to do is create a "hyperlink construction string" in VBA, then assign them to the value of the textbox. So, something like:

Me.Field.Value = {link: www.google.com : "Google"} & "; " & {link: www.yahoo.com : "Yahoo"}

...would result in this being in the text box:

Google; Yahoo

My problem is, I can't seem to figure out the syntax to create an individual link in the textbox without making the entire textbox a single hyperlink, which isn't gonna work.

I was working with a few solutions that I've found. I read that this would create the link in the way I need, but it just comes through as literal text with the pound signs:

"Google # www.google.com # Some Argument"

I also tried setting the textbox to rich text, then setting the value to include rich text code for a hyperlink... but that's not working:

"{\field{\*\fldinst HYPERLINK ""http://www.google.com/""}{\fldrslt http://www.google.com}}"

I also thought about designing a Query that will return the hyperlinks. But, I kind of wanted to make it a VBA thing, because I'll have more flexibility in how I create the value. Does anyone have any ideas?

Note: I understand that multiple values should be in a 1:M relational database. They are. But, the requirements of the task are to get all the M values for a 1 entity, then list them out in semi-colon, delimited fashion, which all serve as links to a Details table for the M entity.

Christine
  • 694
  • 6
  • 19

1 Answers1

1

Regular textboxes (text only) don't support this.

It is possible with Rich text textboxes. In contrast to the name, they actually use a subset of HTML, not RTF.

With ideas from here I got this working:

Private Sub cmdInsertHyperlinks_Click()

    Dim url1 As String, url2 As String

    url1 = "D:\tmp\test.jpg"
    url2 = "D:\tmp\test space.txt"

    Me.rText.Value = "<div>" & _
        "<a href = " & url1 & ">file://" & url1 & "</a>" & _
        "  other text between hyperlinks  " & _
        "<a href = " & url2 & ">file://" & url2 & "</a>" & _
        "</div>"


End Sub

Note: the linked thread says you must URL-encode the links (space to %20 etc), but at least for my simple test, that wasn't necessary.

Note 2: You can't have a different display text and link url, at least I didn't get that to work.

Andre
  • 24,160
  • 6
  • 28
  • 67
  • When you say "rich text textboxes," do you mean a standard textbox set to Rich Text? I don't see a control called "Rich Text Textbox." What about a List Box? Is there a way to list the links in a dynamically growing List Box? – Christine Jul 22 '16 at 17:39
  • Yes, that's what I meant. A list box would be a completely different thing, there you can add items dynamically and react to click events of separate items. – Andre Jul 22 '16 at 19:00
  • Actually, the div and a tags don't really make any difference. If you just set the value to "file://D:\tmp\test.jpg" without the div and a tags, it'll create the link just the same. – Christine Jul 22 '16 at 21:58
  • @Hill, thank you very much--adding file:// at the beginning of the filename did exactly what I needed. – DRC Sep 20 '17 at 15:37