Confused about combo-boxes and selection

  • Thread starter Thread starter David
  • Start date Start date
D

David

I have a combo box and when an item is highlighted (or
whatever the correct term is) I need to enable a button.
Conversely, the button must be disabled until an item is
selected. I was given some advice on this before but it
was incorrect as it does not work in all cases.
How do I tell if a combo box item is selected and how can
the button detect it and enable or disable itself?

The solution must work on initial display (when the combo
box may be empty) and upon return to the form after the
button is pressed.
 
In the click event of the combobox

if <controlname>.listindex < 0 then
'Not selected
button.enabled = false
else
'Selected
button.enabled = true
end if

if the box is empty or not selected then
<controlname>.listindex = -1
You can put the same code in the form_current event if you
are using bound forms

But to catch all possibilities, I would leave the button
enabled at all times, and use the listindex check in the
buttonClick event

if <controlname>.listindex < 0 then
'Not selected
msgbox "Please select ..."
exit sub
end if
else
 
Back
Top