Home  |   French  |   About  |   Search  | mvps.org  

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

In Memoriam

Terms of Use


VB Petition

Forms: Use ControlTipText to display textbox value

Author(s)
Dev Ashish

(Q)    Some of the records in my database have values that are longer than the width of the bound control on the form.  Is there a way I can display the complete text without requiring the user to click in the field and using arrow keys to read the value?

(A)    Access Form controls have a property called ControlTipText (what you see in the yellow tooltip popup if you place the mouse over a control for some time).    This property can be easily used to display the complete value of the actual control itself. 

        Note that this method will not work for continuous forms since changing a control's property in continuous mode affects all records being displayed.

        Also note that sShowToolTip will work for comboboxes as well. Given the assumption that most combos have two columns, a bound ID column and a display column, the sub will update the display with the unbound column's value. I've set the condition for columnCount=2 because if you have more than 2 columns, it's tricky determining which column's value you want to display in the combobox.

        Paste this sub in a new module.

'**************** Code Start **************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Public Sub sShowToolTip(frm As Form)
Dim ctl As Control, i As Integer
    On Error Resume Next
    For Each ctl In frm.Controls
        With ctl
            If .ControlType = acTextBox Then
                .ControlTipText = .value
            ElseIf .ControlType = acComboBox Then
                If .ColumnCount = 2 And .value <> "" Then
                    .ControlTipText = .Column(.BoundColumn)
                End If
            End If
        End With
    Next ctl
    Set ctl = Nothing:    Set frm = Nothing
End Sub
'**************** Code End ****************

Now from the Current event of the form, call this sub as

Private Sub Form_Current()
    Call sShowToolTip(me)
End Sub

If you need to update the ToolTip when the contents of a textbox changes as well, simply call the sub again from the AfterUpdate event of the control.

Private Sub SomeTextBox_AfterUpdate()
    Call sShowToolTip(me)
End Sub


© 1998-2010, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer