?
Solved

Calling a subroutine by clicking a link in a textbox.

Posted on 2002-07-08
3
Medium Priority
?
161 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 400 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 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