Solved

Calling a subroutine by clicking a link in a textbox.

Posted on 2002-07-08
3
155 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now