I struggled for some time attempting to find a way to prevent a combobox drop-down menu from deploying when clicked without disabling the combobox or automatically setting the focus to another control when the combobox enter event is raised. (Most solutions I found by searching involve things like setting the focus on another control anytime the combobox's enter or click events occur, or more complicated alternatives involving additional hidden controls and/or disabling the combobox in some way.)
In the particular case I was working on, none of these options was acceptable because I needed the control to remain enabled and retain the focus, yet, when a certain condition was met, I still didn't want the combobox to deploy even when the down-arrow was clicked.
I stumbled upon an extremely simple solution, which I have copied below and explained.
I imagine that this is not a very common requirement and also that this solution or something similar might be old news to more experienced users but, even so, I didn't find anything quite like it by searching so I am sharing it and I do hope someone finds it useful in the future.
Code:
'PURPOSE: prevent a combobox drop-down menu from deploying when the drop-down square/arrow is clicked, but without
'disabling the combobox and still enabling it to retain focus when the "text part" of the combobox to the
'left of the drop-down square is clicked
'EXPLANATION: The combobox in this example is called, cmbVendor. The parent form contains a
'hidden (but not invisible) textbox called, txtH. This tiny piece of code is placed in the combobox's mouseDown event.
'When the drop-down arrow (or anywhere in the small square that contains the dropdown arrow) is clicked,
'the drop-down will NOT deploy and the focus will automatically switch to the hidden textbox, txtH.
'However, if the user clicks in the text part of the combobox to the left of the drop down, the combobox
'will still get the focus.
'The value of the parameter X is the horizontal coordinate in twips of where you click, every time the combobox mousedown
'event occurs. All that is necessary is to figure out the X coordinates of the leftmost and rightmost extremes
'of just the drop-down square and then test if X is > the leftmost edge or <= the rightmost and switch the
'focus if it is. In the example below, the leftmost is 5745 twips and the rightmost is 6000.
'-----------------------------------------------------------------------------------------------------------
Private Sub cmbVendor_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X >= 5745 And X <= 6000 Then
Me.txtH.SetFocus
'You can use the line below to determine the coordinates. Remove the comment, go to Access and switch the form to form view.
'carefully click around the left and right edges of the drop-down square to determine its left and right extremes
'Msgbox X
End If
End Sub