Do you Double-click on Combo Boxes?

Published on
15,369 Points
6 Endorsements
Last Modified:
Editor's Choice
Community Pick
I do… Ever since I discovered the short-cut in Access 2.0, notably in the property sheets, I double click on all sorts of combo boxes — or their labels — to select the next item in the list.

This was a smart interface choice by the Access development team: you almost never need to double-click on a word in a combo box to select it, for example, and the feature is especially useful for combo boxes with short lists: “Yes/no”, “not indexed / indexed (with duplicates) / indexed (without duplicates)”, etc. It speeds up design and avoids having to create check boxes for properties that are really just flags.

To implement the same feature in your own applications, one line of code is enough (or three here, for readability).
Private Sub MyCombo_DblClick(Cancel As Integer)
    With MyCombo
        .Value = .ItemData((.ListIndex + 1) Mod .ListCount)
    End With
End Sub

Open in new window

This sets the combo to the next item (list index plus one), wrapping to zero after the last item (modulo list count). The event can also be cancelled, but that is rarely useful.

It's not much code, but I use it so often that I normally create this function in the module dealing with the user interface:
Function ComboNextItem(cbo As ComboBox, Optional OrNull As Boolean)
' Selects the next item in the passed combo box.
' Set 'OrNull' to True (or 1) to select Null after the last item.

    If OrNull Then
        ' let Null happen by overflow of list index
        With cbo
            .Value = .ItemData(.ListIndex + 1)
        End With
        ' wrap list index to list count
        With cbo
            .Value = .ItemData((.ListIndex + 1) Mod .ListCount)
        End With
    End If
End Function

Open in new window

Each combo box in my application then gets the following “On Dbl Click” property:

    = ComboNextItem(MyCombo)

or, in the rare cases where Null makes sense,

    = ComboNextItem(MyCombo,1)

This reduces the clutter in the form modules: no need for highly redundant event handlers for each and every combo on the form.

I hope you will find this trick useful!

Markus G Fischer

This article is part of the EE-book unrestricted Access.
Ask questions about what you read
If you have a question about something within an article, you can receive help directly from the article author. Experts Exchange article authors are available to answer questions and further the discussion.
Get 7 days free