Tooltip with textbox when hovering over label

Liamvm

New member
Local time
Today, 19:33
Joined
Dec 10, 2024
Messages
2
Hello,

I am trying to create a tooltip via VBA in which a text message appears when I hover over a certain graphic (or ActiveX label) with my mouse.

I manage to make a messagebox appear, but here it is necessary to keep pressing ‘OK’ to make it disappear.

Is there any way to make just the text appear without having to confirm?

I've already skimmed the entire internet, but I can't find a solution.

Thanks for any help

(PS I currently still a VBA-noob, but am trying to understand it)

Translated with DeepL.com (free version)
 
Hi. Welcome to AWF!

You could try using a custom form instead. You can also set it to auto close after a set amount of time.
 
Hi. Welcome to AWF!

You could try using a custom form instead. You can also set it to auto close after a set amount of time.
Hey,

how could I make a custom form?

For example when i hover over label 'TEST' I want the message 'Welcome' to appear.
Do you have any link I can use to try this?

Thank you in advance
 
I am trying to create a tooltip via VBA in which a text message appears when I hover over a certain graphic (or ActiveX label) with my mouse.
Not sure about graphics or Active X labels but for native Access controls you can set the "ControlTip Text" property of the control using the Other tab of the property sheet.
 
For context - sensitive help, I've always found it best to just have a text box on your form that the user can't muck with. When a control gains focus, set the text in the "Help box" by loading the record from your "Help file" that matches. No need worrying about tool tips, and your users ALWAYS have the help they need.

Always did this from a help file (records have ID, form name, field name, and help text as their main fields, can toss in Language_ID if you are looking to deploy a multi lingual application) and included a utility for customers to update the help to match their business language.

Once you start doing this, it becomes second nature. Very intuitive for most users. They NEVER look at the help until they need it, and it's ALWAYS right there where they need it.
 
I'm with Mark_ on this one. I always had a "Hints" box that was unbound, and the form's functional controls all had .GotFocus and .LostFocus events to load or erase the Hints box. The only problem that ever occurred was if the hint was SO complex as to overflow the Hints box, I had to add scroll bars. But that was so rare as to not be an issue about 98% of the time.
 
Hey,

how could I make a custom form?

For example when i hover over label 'TEST' I want the message 'Welcome' to appear.
Do you have any link I can use to try this?

Thank you in advance
Just create a popup form and call it, instead of MsgBox , when you hover on the label.
 
The NO CODE solution is to use ToolTips. Just add your text to the ControlTip Test property for the control and when someone hovers on the control, the text pops up and then goes away when you move on.

1733855482670.png
 
I dare say you could also use a function there, to make it data driven?
 
Hello,

I am trying to create a tooltip via VBA in which a text message appears when I hover over a certain graphic (or ActiveX label) with my mouse.

I manage to make a messagebox appear, but here it is necessary to keep pressing ‘OK’ to make it disappear.

Is there any way to make just the text appear without having to confirm?

I've already skimmed the entire internet, but I can't find a solution.

Thanks for any help

(PS I currently still a VBA-noob, but am trying to understand it)

Translated with DeepL.com (free version)
You might get some useful ideas on custom tooltips from Greg Regan's presentation:


I should add that Greg's method eliminates the often flaky behavior of the built-in tooltips.
 
Control tip text is slow and unreliable. There are better methods available
You could also look at several different approaches I use instead of control tip text:

 
Control tip text is slow and unreliable. There are better methods available
You could also look at several different approaches I use instead of control tip text:

@isladogs It may only be me and my settings, just thought you may want to double check your sample database downloaded from your site.

2024-12-13_10-31-07.jpg

Clicking Form 1 button is OK.
In case of Form 2 and Form 3 buttons, If I move my mouse a little fast (not too much) the above error shows up.
There are only two ways out of the error :
Using task manager and ending the task, or dragging the error messagbox in a location where the OK button is not on top of the form, and then clicking it.
 
Last edited:
I wasn't suggesting that the built in "feature" was the best option. Only that it is a no code option which might just do the trick. The only time you would have a data driven solution is if you have many controls on many forms where you want to display the same information. Otherwise, it is one for one so it makes no difference to your work if you use the tool tip to hold the message or a table and in fact, using the tool tip is simple, if perhaps a little sluggish.

I am all about data driven solutions as you know but I don't see one here. I'm sure someone will enlighten me though.
 
@isladogs It may only be me and my settings, just thought you may want to double check your sample database downloaded from your site.

View attachment 117473
Clicking Form 1 button is OK.
In case of Form 2 and Form 3 buttons, If I move my mouse a little fast (not too much) the above error shows up.
There are only two ways out of the error :
Using task manager and ending the task, or dragging the error messagbox in a location where the OK button is not on top of the form, and then clicking it.
I've used this approach in multiple databases over the last 20 years or so without problems

I've been trying to replicate the issue you described on my desktop PC but failed no matter how fast and for how long I moved the mouse over the forms.

Nevertheless I can see why it could happen and I did eventually manage to trigger the error when I tested on a low-spec Windows tablet.
The solution would be to only update the information displayed on mouse move where it has changed since the last mouse position.
However, for me at least its a non-issue in normal usage.
 
I've used this approach in multiple databases over the last 20 years or so without problems

I've been trying to replicate the issue you described on my desktop PC but failed no matter how fast and for how long I moved the mouse over the forms.

Nevertheless I can see why it could happen and I did eventually manage to trigger the error when I tested on a low-spec Windows tablet.
The solution would be to only update the information displayed on mouse move where it has changed since the last mouse position.
However, for me at least its a non-issue in normal usage.
Thanks for checking. My PC is a monster, made for working on complicated 3D objects.
I didn't try to trap where the error occurs. Maybe my CPU clock rate is too high for these kind of operations.
Again, thanks.
 
@KitaYama

See if changing this code in the MouseMove events helps:
Code:
' ...
  If Not strText = "Enter the last name" Then
    strText = "Enter the last name"
    Me.lblInfo.Caption = strText
    DoEvents
    If IsTTSEnabled Then voc... etc
  End If
' ...
It might not help, but can't hurt to try. The MouseMove event fires repeatedly and can tax your processor even if it doesn't raise the error you saw.

(All this would be better coded into a separate function (or class) to avoid having to repeat in each MouseMove event.)
 
@KitaYama

See if changing this code in the MouseMove events helps:
Code:
' ...
  If Not strText = "Enter the last name" Then
    strText = "Enter the last name"
    Me.lblInfo.Caption = strText
    DoEvents
    If IsTTSEnabled Then voc... etc
  End If
' ...
It might not help, but can't hurt to try. The MouseMove event fires repeatedly and can tax your processor even if it doesn't raise the error you saw.

(All this would be better coded into a separate function (or class) to avoid having to repeat in each MouseMove event.)
I don't have access to my PC until Monday.
I'll test as soon as I'm back to my desk.

Thanks for taking your time and helping.
 
I haven't posted in a while... this is an unpolished proof of concept I had fun with for a moment. It works like this:
1. A function is assigned to the mouse move event of each control when the form loads
2. The function starts a timer and a flag to show the tooltip
3. On timer, another timer cycle is started to hide the tooltip through the flag
4. Once the timers are set, accHitTest is called to get a handle to the control under the cursor (it fails if no control is under the cursor, so you have to catch it)
5. Depending on the flag, the tooltip will show or hide
6. The tooltip is an invisible label control whose text is set form the tag property of each control

Code:
Option Compare Database
Option Explicit

Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI: X As Long: Y As Long: End Type
Private pt As POINTAPI
Private hoveredCtl As Object
Private shouldVanish As Boolean
Private Const TOOLTIP_SHOW_DELAY As Long = 600
Private Const TOOLTIP_HIDE_DELAY As Long = 1200
Private Const TOOLTIP_OFFSET As Long = 250


Function CallTooltip()
    shouldVanish = False
    Me.TimerInterval = TOOLTIP_SHOW_DELAY
End Function

Private Sub Form_Load()
    Dim ctl As Control
    For Each ctl In Me.Controls
        ctl.OnMouseMove = "=CallTooltip()"
    Next ctl
End Sub

Private Sub Form_Timer()
    
    If shouldVanish = False Then
        Me.TimerInterval = TOOLTIP_HIDE_DELAY
        GetCursorPos pt
        
        On Error Resume Next
        Set hoveredCtl = Me.accHitTest(pt.X, pt.Y)
        With Me.tooltip
            .Visible = True
            .Top = hoveredCtl.Top - TOOLTIP_OFFSET
            .Left = hoveredCtl.Left
            .Caption = hoveredCtl.Tag
            shouldVanish = True
        End With
        On Error GoTo 0
    Else
        Me.tooltip.Visible = False
        Me.TimerInterval = 0
    End If
    
End Sub

I hope it works, I hope it helps, I hope it's simple enough
 

Attachments

You can also take a look at post #7 in this thread. I posted a sample Db that shows how you can use a form as a popup.
 

Users who are viewing this thread

Back
Top Bottom