Mimicking hyperlink behaviour (tooltip, cursor) in VBA (1 Viewer)

Notiophilus

Registered User.
Local time
Today, 22:45
Joined
Jan 18, 2015
Messages
42
[SOLVED] Mimicking hyperlink behaviour (tooltip, cursor) in VBA

I want to use my own VBA hyperlink function, which is just FollowHyperlink + error handling to copy broken links to clipboard, to replace the default =[Title]#[Link]#.

It works perfectly, but is there a way to mimic, in a report

  • the very useful "tooltip = URL" behaviour of the original? Okay, scratch that, I found a solution literal seconds after posting this. And then I found a better one.*
  • cursor changing to hand on mouseover? (pretty sure this one is easy and I've simply been looking in the wrong places)
* Tooltip on txtTitleAll_MouseOver.
Code:
    On Error GoTo ErrHandler
    If Me.Link <> txtTitleAll.ControlTipText Then       'prevents endless flickering on mouseover
        Application.Echo False
        If Not IsNull(Me.Link) Then
            txtTitleAll.ControlTipText = Me.Link
        Else
            txtTitleAll.ControlTipText = ""
        End If
        Application.Echo True
    End If
    
ExitHandler:
    Exit Sub
    
ErrHandler:
    Application.Echo True
    Resume Next
Running Access 2010.
Cheers (and a happy new year)
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:45
Joined
May 7, 2009
Messages
19,227
instead of txtTitleAll_MouseMove,
move your code to the Report's MouseMove Event
to minimised flicker.

Set its Key Preview Property to Yes first.
Code:
Private Sub Report_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Me.txtTitleAll.ControlTipText = ""
    If Not IsNull(Me.Link) Then _
        Me.txtTitleAll.ControlTipText = Me.Link
End Sub
 

Notiophilus

Registered User.
Local time
Today, 22:45
Joined
Jan 18, 2015
Messages
42
Thanks! That code works too, though it doesn't recognise changes from [link] to [no link] until you pass over two records, for some strange reason. I ended up using an API function to change the cursor and it works very smoothly, with zero flicker.

Final result, for the benefit of anyone with similar intentions and similarly little patience:

Code:
Private Sub txtTitleAll_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    If Not IsNull(Me.Link) Then MouseCursor (IDC_HAND)       'hand cursor when link

    On Error GoTo ErrHandler
    If Nz(Me.Link, "") <> txtTitleAll.ControlTipText Then    'only change controltip when necessary
        Application.Echo False
        txtTitleAll.ControlTipText = Nz(Me.Link, "")
        Application.Echo True
    End If
    
ExitHandler:
    Exit Sub
    
ErrHandler:
    Application.Echo True
    Resume Next
    
End Sub

[link to MouseCursor function]

Let that be a lesson to me. Why is it that I always find a solution about five seconds after I finally work up the courage to ask the question? :rolleyes:

P.S. for anyone with time to kill: In my internet wanderings I noticed a lot of people wanted to change the cursor without resorting to APIs. Is there a reason to avoid them, besides unfamiliarity?
 

Users who are viewing this thread

Top Bottom