Solved

Calling a subroutine by clicking a link in a textbox.

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reading the Contents of a Directory In Access VBA 5 71
Run code from text file in vb 1 65
Add and format columns in vb6 7 58
Error with a code discussed on this page 5 16
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

832 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