ControlTip Text and Time Delay
Most of the Controls on a Form like Command Buttons, Labels, Text-Boxes and others have the Property ControlTip Text. This can be set with a Value of up to a maximum length of 255 characters, either manually during design time or through Visual Basic. The text is displayed when the Mouse Pointer rests on the Control for a few seconds. This is useful to inform the User to do certain action, like Click or Double-Click, on the Control to run a Program or Macro attached to it.
The Toolbar Buttons above also have this feature programmed with the Screen Tip Property Value (another name for ControlTip Text) to give clues to the User as to what the control does or what to do to use it. For example when you point the Mouse pointer on the Copy Toolbar Button it will show Copy (Ctrl+C) indicating that either Click on the Button to Copy the selected Text/Control or use Ctrl+C to get the same result.
The time delay is programmed into this action assuming that the Mouse Pointer rests on the Control because the user probably doesn't know what it does and needs some help to indicate what he/she should do to use it or what result one can get by using it.
Here, we will concentrate on Controls on a Main Switchboard (Control Screen), like Command Buttons, List-Boxes and how to achieve the same result without the time delay that needs for the ControlTip Text Property.
There is another Property named Tag placed near to the ControlTip Property; its function is not clearly defined and free to use, as you wish. The value in this Property will not affect the Control in any way and will not have any side effects to other Properties either. You can write a short story into the Tag Property, if you can limit your story to 2048 characters.
We are going to use this Property of different Controls on the Main Switchboard of a sample database to give clues to the User instantly what each control does or what to do (like Click or Double-Click) to run the Program or Macro attached to them.
You must select each control and display their Property Sheet(View – -> Properties) and type the Value, you would like to display, into the Tag Property. This text will appear instantly in the Label with dark background (you can use any color you like) placed at the bottom of the Form when the Mouse is moved over a Control with Tag value set and programmed.
An image of a sample Main SwitchBoard with the above trick is given below:
A Label with 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 displayed on the image is attached to the Tag Property of the List-Box with Forms‘ Names.
To display the clue and to remove it when the Mouse moves out of the Control we need to run 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.
The sample Code in the On Mouse Move Event Procedure of the Reports Command Button is given below that displays: Open Report SwitchBoard in the LBLTIP label below, 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) appears and stays there till the mouse moves over 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
Even though the Detail Section Mouse Move Event Procedure Code has no change; repeating all three lines of code for each control is excess work. The IF. . .Then statement is used to test and prevent setting the LBLTIP Caption value repeatedly.
We can implement this with a single line of code, if we write a common routine and place it in a Global Module (standard Module) and call it with a single line of code with necessary Parameters. Such a Function is given 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:
- Name of the Form from where the Function is called.
- The LBLTIP.Caption text to display. 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 Form-level (in our example from Detail Section) to display the welcome message after removing the earlier contents.
- The Optional xswitch parameter is used for display control. Value of 1 will display the Text value passed through the Second Parameter or else it will display a welcome message to the active User replacing earlier text in the LBLTIP control.
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
You can download the sample database (Access2000 Version) from the Link below and try it out.