ControlTip Text in a Label

accvbalearner

Registered User.
Local time
Today, 02:11
Joined
Jan 3, 2013
Messages
42
Hi All,

Thanks in advance for any help that you can provide.

I have a form with many fields (25+), some with list boxes, some combo boxes and some regular text boxes. What I would like to do is have a label or text box in the form that will display the controltip text for the active control on the form. As the user moves from field to field completing the form the label/text box will change to that fields controltip. Users don't always use the mouse, sometimes they tab through so the hover event isn't effective in providing the help they may need to complete the form.

I'm not even sure where I should start this in VBA Code because I don't want the focus to ever be on this "help" label, it should just update as the user moves through the form.

I have tried using a Text Box with the Data Control Source set as '=[Screen].[ActiveControl].[Name]', but all this shows is the name of the Active box, is there a way to reference the ControlTip Text this way? I cannot use the Other Tag feature in Object Properties because it is already being used as a null check to make sure that the required information in the form is entered before taking the record.

Any help or ideas would be much appreciated.

Take Care.
 
One way you could do this would be to put the following code in the On Got Focus event of each control on your form;
Code:
Me.YourTextBox = Me.ThisControlsName.ControlTipText
 
Hi All,

An update to the issue, I just tried setting the Text box Data Control Source to =[Screen].[ActiveControl].[ControlTipText] and it shows the control tip for the first box selected, however after that, it doesn't update as you move through the form. It should refresh every time the focus changes in the form.

Any help is much appreciated.

Take Care,
accvbalearner
 
You would need to set the GOT FOCUS event for every control. You can do that with code in the On Open event of the form so that you don't need to manually go do that for each one.

First you need code to set the caption (create it in a STANDARD MODULE, not a form, report, or class module).

Code:
Function SetControlTipCaption(ctl As Control)
    If Len(ctl.ControlTipText & vbNullString) > 0 Then
       Forms!FormNameHere.LabelControlNameHere.Caption = ctl.ControlTipText
    Else
       Forms!FormNameHere.LabelControlNameHere.Caption = vbNullString
    End If
End Function

Next you need to be able to set that in each GotFocus event of the controls
Code:
Private Sub Form_Open()
   Dim ctl As Control
 
   For each ctl In Me.Controls
        Select Case ctl.ControlType
             Case acTextBox, acComboBox, acListBox, acOptionGroup, acCheckBox
 
                     ctl.GotFocus = "=SetControlTipCaption([Screen].[ActiveContol].[Name])"
        End Select
End Sub

That is untested "Air Code" so it may require some fixes.
 
Last edited:
boblarson & John Big Booty,

Thanks for the quick replies, ya'll have replied so fast, that I haven't had time to try either idea yet. I will try both ideas and see which one works best and get back to you as quick as I can.

Some of my boxes in the form already have an action in the OnGotFocus Event, can your recommendations just be included at the end of the Event outside of any logic statements already there and working correctly? I hope so!

Thanks for your input!

Take Care,
accvbalearner:D
 
Even if your text boxes already have code in their On Got Focus events my solution can still be applied, just insert the code either before or after the existing code.

However I'd probably be experimenting with Bob's solution as it will require far less coding given the number of control you have.
 
John Big Booty,

Thanks for the recommendation.

I was thinking that your code would be easiest to enter because it would be just one line in each GotFocus Event. However, when I tried it I got this error message "You can't assign a value to this object." It would seem to me that bob's idea would be much more time consuming if the 2nd set of code he provided must be entered into each GotFocus event. I don't really understand that section. Can you give me a rundown on what that 2nd set of code will do?

Here is the code I'm using for your idea, HelpText is the name of the TextBox:

Private Sub Area_GotFocus()
Me.HelpText = Me.ActiveControl.ControlTipText
End Sub

For now, I am entering the help text that I want the user to see into each of the ControlTip Text Fields in the Other Tab of Form Properties, then I will try boblarson's idea. So far as I am testing it I have found that once I start typing in a Field the HelpText Box updates to correct ControlTipText by using my original idea, but it doesn't work at all if you click a field with the Mouse or tab through the form. If you don't attempt to enter data it doesn't update, it just stays with the last field's ControlTipText.

Thanks again for all the help! This is the best site for getting help with this kind of stuff.

Take Care,
accvbalearner:D
 
I'm not sure why my code is giving you that error :confused: Unless it is has code in its it's Control Source

At any rate using;
Code:
Me.HelpText = Me.ActiveControl.ControlTipText
will be far simpler to implement, as you can simply paste it into each of the Got Focus events, not sure why I didn't think of it :(
 
It’s not as easy as it would appear.

If the information in the ControlTipText is displayed in a Label on OnEnter then that will happen.

At the same time, the Mouse will display the ControlTipText in the normal way.

Both are not the same thing and so the Label will display the Focus and the Mouse could display something else.

You will need to define what you want to see.

Chris.
 
John Big Booty,

You are correct, when I tried to use your code recommendation I forgot to remove =[Screen].[ActiveControl].[ControlTipText] from the Control Source section of the Data tab in the Form Properties. Once I cleared that out your idea worked like a charm!

It would seem that there would be a shorter way to do this instead of copying the same code into 25+ OnGotFocus Events, but until I can figure that out I'll stick with this. Thank you for your help and ideas!

Take Care,
accvbalearner
 
It would seem that there would be a shorter way to do this instead of copying the same code into 25+ OnGotFocus Events, but until I can figure that out I'll stick with this. Thank you for your help and ideas!
I gave you the way to do that. But apparently it didn't register.
 
boblarson,

Sorry, it didn't. I was reading through it last night and it appeared that I had to place that code sample into every GotFocus event on the form.

If you have time, can you give me a quick rundown on how I need to apply your code? I understand how to apply the Function but not the 2nd set. I still have several forms that will need this same type of coding and if your idea is using a public function it can be referenced by any of the forms.

Thanks in advance.

Take Care,
accvbalearner
 
JBB said to use this:
Code:
Me.HelpText = Me.ActiveControl.ControlTipText

So, if you put that into a function in the form's module like this:

Code:
Function SetFocusEvent()
   Me.HelpText = Me.ActiveControl.ControlTipText
End If

Then you can just put this code of mine on the Form's OPEN event:
Code:
Private Sub Form_Open()
   Dim ctl As Control
 
   For each ctl In Me.Controls
        Select Case ctl.ControlType
             Case acTextBox, acComboBox, acListBox, acOptionGroup, acCheckBox
 
                     ctl.GotFocus = "=SetFocusEvent()"
        End Select
End Sub
 
Oh, and to give credit where credit is due, I got that method from ChrisO.
 
Or, if you want to put even more of the code in a standard module…
Note the use of the OnEnter event and not the GotFocus event which you say may already be in use.
Code:
Public Sub SetControlTipHandler(ByRef frm As Form)
    Dim ctl As Control
    
    For Each ctl In frm
        Select Case ctl.ControlType
            Case acTextBox, acComboBox, acListBox, acOptionGroup, acCheckBox
                ctl.OnEnter = "=HandleControlTipText([" & ctl.Name & "])"
                
        End Select
    Next ctl

End Sub


Public Function HandleControlTipText(ByRef ctl As Control)

    ctl.Parent.lblControlTipText.Caption = ctl.ControlTipText

End Function

And simply call it from the Form as:-
Code:
Private Sub Form_Open(ByRef intCancel As Integer)

    SetControlTipHandler Me

End Sub

But the problem still exists that the data is stored in the ControlTipText. The Label which displays the Text OnEnter can be different to the Text which is displayed when the mouse moves over another Control. Putting the Text in a Label will not stop the ControlTipText from working so you will have two prompts on the screen which may be different.

Chris.
 
And as by part explanation…

The code is broken down into two distinct procedures.
The first is to direct program flow to where to get the Text.
The second is to direct the program as to how to get the Text.

Sub SetControlTipHandler sends the OnEnter event to Function HandleControlTipText, that is the where.
Function HandleControlTipText determines how to get the Text.

The where and how of getting the Text can be thought of as Atomic in database parlance. Neither has anything to do with the other and they should not interfere with each other.

If circumstances change with the where, perhaps another Control type is added, then the code is changed in the where Sub.

If circumstances change with the how, I think they will (should), then the code is changed in the how Function.

But they are two distinct procedures and should be thought of as such.

Chris.
 

Users who are viewing this thread

Back
Top Bottom