Solved

Calling a subroutine by clicking a link in a textbox.

Posted on 2002-07-08
3
160 Views
Last Modified: 2010-05-02
Hello all,
          I need to know how to create a hyperlink in a textbox (or richtextbox) that when clicked DOES NOT open a browser window, I would like it to call a subroutine instead with the clicked text as a parameter instead.

I also don't want the whole box clickable, or to call the routine, just a specfic word in the box.

For instance if the textbox contained, "Hello my name is Joe.", when the user clicks on Joe (which should be underlined and blue to look like a hyperlink) a subroutine would be called and "Joe" would be stored in the variable.  BUT, clicking on any other word would do nothing.

Thanks for any help or suggestions in Advance,
Aaron
 
0
Comment
Question by:Cide
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7139695
Try this:

Put a Multiline TextBox with scrollBars and write this code:

Private Sub Text1_DblClick()
If Text1.SelText <> "" Then myPro (Text1.SelText)
End Sub


Sub myProc(t As String)
MsgBox t
'your code goes here
End Sub

Hope this helps!

-priya
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 100 total points
ID: 7140082
Here is an example of doing this with a richtextbox, you cannot set colours etc on the standard textbox anyway so try this out and see if you like it:

Private Sub Form_Load()
    Dim intPos1 As Integer
    Dim intPos2 As Integer
    With RichTextBox1
        .Text = "Hello this is some text that I want to test the linking thing with"
        For i = 1 To 5
            intPos1 = InStr(intPos2 + 1, .Text, " ")
            intPos2 = InStr(intPos1 + 1, .Text, " ")
            .SelStart = intPos1
            .SelLength = intPos2 - intPos1
            .SelBold = True
            .SelColor = vbBlue
            .SelUnderline = True
        Next
        .SelStart = Len(.Text)
    End With
End Sub

Private Sub RichTextBox1_Click()
    Dim intPos1 As Integer
    Dim intPos2 As Integer
    With RichTextBox1
        intPos1 = InStrRev(.Text, " ", .SelStart)
        intPos2 = InStr(.SelStart, .Text, " ")
        If .SelColor = vbBlue And .SelUnderline And .SelBold Then
            FollowLink Mid(.Text, intPos1, intPos2 - intPos1)
        End If
    End With
End Sub

Private Sub FollowLink(ByVal FollowedText As String)
    MsgBox "You Clicked on the Link : " & FollowedText
End Sub
0
 

Author Comment

by:Cide
ID: 7140737
I love it!  Good work!  :)

Aaron
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question