Microsoft KB Archive/132379

= ACC2: Simple Method for Creating ToolTips for Form Controls =

Article ID: 132379

Article Last Modified on 11/6/2000

-

APPLIES TO


 * Microsoft Access 2.0 Standard Edition

-



This article was previously published under Q132379



SUMMARY
This article describes a method that you can use to add custom ToolTips (brief descriptions that appear when the mouse pointer moves over particular controls) to forms.

This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Access Basic, please refer to the "Building Applications" manual.



MORE INFORMATION
This method creates ToolTips by using a text box, the Tag property of form controls, and a custom function that is triggered by the MouseMove event of form sections and controls. For example, when you move the mouse pointer over a particular control, the MouseMove event triggers the custom function. The function moves a text box displaying a brief description stored in the control's Tag property under the control.

This method uses a single text box to display the ToolTip messages for all the controls. Be aware, however, that the size of the text box is not adjusted for descriptions of varying lengths. To avoid cutting off the ToolTip text, use a set number of characters for the control descriptions.

To add custom ToolTips to a form, follow these steps.

 Open the sample database NWIND.MDB, and open the Customers form in Design view.  Add a text box to the Customers form and set the text box control's properties as follows:

     Name: ToolTip Visible: No     BackColor: 8454143

NOTE: You do not need the label for this control; you can delete it.   Add a command button to the Customers form and set the command button control's properties as follows:

     Name: MyButton. Tag: My Button OnMouseMove: =ShowToolTip("MyButton")   On the View menu, click Code and type the following function in the Module window:

Function HideToolTip Dim z As Integer On Error Resume Next If Me!ToolTip.Visible = True Then Me!ToolTip.Visible = False 'Turn off the ToolTip. z = SysCmd(SYSCMD_CLEARSTATUS) End If      End Function   Set the Customers form detail section's OnMouseMove property as follows:

     =HideToolTip

Note: This procedure must be called from the MouseMove event of any section where you use a control with a ToolTip. </li> Close and save the Customers form.</li>  Create a new module and type the following line in the Declarations section:

<pre class="fixed_text">     Option Explicit </li>  Type the following function:

Function ShowToolTip (ShowControl As String) Dim MyControl As Control Dim MyToolTip As Control Dim z as Integer Const Separator = 80 On Error Resume Next

Set MyControl = Screen.ActiveForm(ShowControl) Set MyToolTip = Screen.ActiveForm!ToolTip

If MyToolTip.Visible = False Then MyToolTip = MyControl.Tag MyToolTip.Left = MyControl.Left + (Separator * 2) MyToolTip.Top = MyControl.Top + MyControl.Height + Separator MyToolTip.Visible = True

' Optional: Display ToolTip on the Status Bar. z = SysCmd(SYSCMD_SETSTATUS, MyToolTip.value) End If

End Function </li> Open the Customers form in Form view and move the mouse pointer over the command button to display the ToolTip message under the button.</li></ol>

NOTE: The MouseMove event of the detail section may not run and the ToolTip may remain visible if you rapidly move the mouse pointer to a control without a ToolTip. To ensure that the ToolTip turns off, call the same function from Step 6 on the MouseMove event of controls that do not display a ToolTip.

<div class="references_section">