Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

ControlTip Text and Time Delay

Introduction

Most of the controls on a Form—such as Command Buttons, Labels, Text Boxes, and others—have a ControlTip Text property. This property can hold text up to a maximum length of 255 characters, which can be set either manually during design time or programmatically through VBA.

The text entered here is displayed when the mouse pointer hovers over the control for a few seconds. This is particularly useful for providing quick hints or instructions to the user, such as prompting them to click or double-click a Control to execute a program or macro attached to it.

Similarly, Toolbar Buttons in Access also feature this capability through their ScreenTip property (which functions the same way as ControlTip Text). These small pop-up hints guide users by explaining what each button does or by suggesting keyboard shortcuts.

For example, when you point to the Copy toolbar button, the tooltip displays “Copy (Ctrl+C)”, indicating that you can either click the button or press Ctrl+C to copy the selected text or control.

This brief delay before the tooltip appears is intentional—it assumes that if the user leaves the mouse resting on a control, they may be uncertain about its function. The tooltip then provides helpful information about the control’s purpose or action, improving the overall user experience.

Our own Method without Time Delay

Here, we will implement a new method for the controls on the Main Switchboard (Control Screen)—such as Command Buttons and List Boxes—to provide immediate feedback to the user, without the time delay inherent in the ControlTip Text property.

There is another property, called Tag, located near the ControlTip property in the control’s property sheet. Its function is not predefined and is completely free for custom use. The value stored in the Tag property does not affect the control’s behavior or interact with other properties in any way. In fact, you can store up to 2048 characters of text here—enough to write a short description or even a mini story!

We will use this Tag property creatively on the controls of the Main Switchboard in a sample database. The idea is to instantly display helpful hints or action clues to the user—for example, what each control does or what kind of action (click or double-click) should be performed to run a program or macro associated with that control.

To implement this, open the Property Sheet (via View → Properties) for each control on the Switchboard, and type your desired descriptive text into the Tag property. Then, place a Label control at the bottom of the form (give it a dark background or any color you prefer) to serve as the “instant help bar.”

When the mouse pointer moves over a control with a Tag value set and programmed, the Tag’s text value appears immediately in that label—without any delay—offering the user quick, context-sensitive information.

An image of a sample Main Switch Board with the above trick is given below:


Using the Mouse Move Event

A Label with a dark background (let us call it LBLTIP) is placed at the bottom of the design to display the clues when the Mouse moves over the controls above. The example text shown in the image was saved in the Tag Property of the ListBox along with the Forms' Names.

To display the clue and to remove it when the Mouse moves out of the Control, we need to run a few lines of VBA Code at two places. On Mouse Move Event Procedure of the Control, as well as at the Detail Section of the Form, to remove the text and replace it with some general message text or a zero-length string to keep it empty.

The sample code in the On Mouse Move Event Procedure of the Reports Command Button is given below. It displays Open Report SwitchBoard in the LBLTIP label Caption text at the bottom of the form when the Mouse is moved over the Command Button.

Private Sub cmdRpt_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Me.LBLTIP.Caption = Me.cmdRpt.Tag Then
    Me.LBLTIP.Caption = Me.cmdRpt.Tag
End If
End Sub

When the Mouse moves out of the Command Button and touches the empty area of the Detail Section of the Form, the LBLTIP Caption changes to Welcome User: Admin (the current MS-Access User Account name) displays and stays there till the mouse moves over to another Control on the Form.

The VBA Code in the Detail Section, On Mouse Move Event Procedure is given below:

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim strtag As String

strtag = "Welcom User: " & CurrentUser

If Me.LBLTIP.Caption <> strtag Then
    Me.LBLTIP.Caption = strtag
End If

End Sub

Limiting the Mouse Move Event

Even though the Detail Section Mouse Move Event Procedure has no change in the Code, repeating all three lines of code for each control is excessive work. The IF... Then the Statement is used to test and prevent setting the LBLTIP Caption value repeatedly.

We can implement this feature with just a single line of code if we define a common routine and place it in a Global Module (Standard Module). Once the routine is in place, it can be called from any control’s event procedure with the necessary parameters, keeping your codebase clean and reusable.

A sample function to achieve this is shown below:

Copy the following VBA Code and save it in a Standard Module:

Public Function ControlTip(ByVal frmName As String, Optional strtext As String = "Welcome User: ", Optional xswitch As Integer = 0)
On Error GoTo ControlTip_Err
With Forms(frmName).Controls("lblTip"
    Select Case xswitch
        Case 1
            If .Caption <> strtext Then
                .Caption = strtext
            End If
        Case Else
            If .Caption <> strtext Then
                .Caption = strtext & CurrentUser
            End If
    End Select
End With

ControlTip_Exit:
Exit Function

ControlTip_Err:
MsgBox Err.Description, , "ControlTip()"
Resume ControlTip_Exit
End Function

The above Function has three Parameters:

  1. Name of the Form where the Function is called.

  2. The LBLTIP.Caption display text. This will be taken from the Tag Property Value of the Control. This parameter is defined as Optional so that this can be called without a value at the Form level (in our example from the Detail Section) to display the welcome message after removing the earlier contents.

  3. The Optional xswitch parameter value is used for display choices. The Value of 1 will display the Text value passed through the Second Parameter, or else it will display a welcome message to the User, replacing the earlier text in the LBLTIP Caption Property.

With the above Function, we can simplify the first two Sub-Routines as given below:

Private Sub cmdRpt_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) 

ControlTip Me.Name, Me.cmdRpt.Tag, 1

End Sub

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    ControlTip Me.Name
    
End Sub

 Demo Database Download

You can download the sample database (Access 2000 Version) from the link given below and try it out.

 

Download Demo ControlTip2k.zip

Share:

No comments:

Post a Comment

Comments subject to moderation before publishing.

PRESENTATION: ACCESS USER GROUPS (EUROPE)

Translate

PageRank

Post Feed


Search

Popular Posts

Blog Archive

Powered by Blogger.

Labels

Forms Functions How Tos MS-Access Security Reports msaccess forms Animations msaccess animation Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Class Module External Links Queries Array msaccess reports Accesstips WithEvents msaccess tips Downloads Objects Menus and Toolbars Collection Object MsaccessLinks Process Controls Art Work Property msaccess How Tos Combo Boxes Dictionary Object ListView Control Query VBA msaccessQuery Calculation Event Graph Charts ImageList Control List Boxes TreeView Control Command Buttons Controls Data Emails and Alerts Form Custom Functions Custom Wizards DOS Commands Data Type Key Object Reference ms-access functions msaccess functions msaccess graphs msaccess reporttricks Command Button Report msaccess menus msaccessprocess security advanced Access Security Add Auto-Number Field Type Form Instances ImageList Item Macros Menus Nodes RaiseEvent Recordset Top Values Variables Wrapper Classes msaccess email progressmeter Access2007 Copy Excel Export Expression Fields Join Methods Microsoft Numbering System Records Security Split SubForm Table Tables Time Difference Utility WScript Workgroup database function msaccess wizards tutorial Access Emails and Alerts Access Fields Access How Tos Access Mail Merge Access2003 Accounting Year Action Animation Attachment Binary Numbers Bookmarks Budgeting ChDir Color Palette Common Controls Conditional Formatting Data Filtering Database Records Defining Pages Desktop Shortcuts Diagram Disk Dynamic Lookup Error Handler External Filter Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Message Box Monitoring Octal Numbers Operating System Paste Primary-Key Product Rank Reading Remove Rich Text Sequence SetFocus Summary Tab-Page Union Query User Users Water-Mark Word automatically commands hyperlinks iSeries Date iif ms-access msaccess msaccess alerts pdf files reference restore switch text toolbar updating upload vba code