ComboBox .Undropdown Method
Combo boxes have a .Dropdown method. But what if you want the opposite: a .CloseDropdown method? This tip from Adam Waller has the answer.
Combo boxes in Access have a .Dropdown method. Several years ago, I asked if there was some way to perform the opposite action. Essentially, I wanted a .CloseDropdown method or a .UnDropdown method. Here was my question on stackoverflow:
Is there a way to toggle the dropdown of a combo box through VBA?
.Dropdownis a method and it only works in one direction. I'm looking for the following functionality:
MyCombo.Dropdown = True MyCombo.Dropdown = False
Obviously the above does not work in MS Access. I'm guessing I'll need to use some sort of hack/workaround for this. I'd like to avoid a
.Requery. That would probably work, but there could be a major performance penalty depending on what the source of the combo box is.
Adam Waller of Access Version Control fame came to the rescue with his answer:
I was dealing with this issue today, and after a lot of trial and error, I discovered that the following works beautifully in Access 2010:
With m_cboLookup .ListWidth = .ListWidth ' Close combo box 'If Len(strSearch) > 3 Then .Dropdown End With
Essentially, you are just setting the list width to the existing list width, but the combo box is closed, presumably to prepare for redrawing at a different size.
In other words, setting the combo box's
ListWidth property to itself is a reliable way to force a combo box's dropdown list to close.