Test if WorkSheet ComboBox list is open

S

Sisilla

Hello All,

I have a combo box on a worksheet. I use the DropDown method to open
the list on the Change event and the KeyDown event to click on a button
if the ENTER key is pressed.

Private Sub cbJobField_Change()
cbJobField.DropDown
End Sub

Private Sub cbJobField_KeyDown(ByVal KeyCode As MSForms.ReturnInteger)
If KeyCode = vbKeyReturn Then
btnFind_Click
End If
End Sub

I would like to change cbJobField_KeyDown so that when the ENTER key is
pressed, if the combo box list is open, it is closed, but if it is
already closed, btnFind_Click is executed. I expect the code would look
similar to the following:

Private Sub cbJobField_KeyDown(ByVal KeyCode As MSForms.ReturnInteger)
If KeyCode = vbKeyReturn Then
If cbJobField.DroppedDown = True Then
Application.SendKeys("{ESC}")
Else
btnFind_Click
End If
End Sub

Is this at all possible? If not, does anyone have any ideas for a
workaround? I appreciate any help.

Thanks!
Sisilla
 
S

Sisilla

Workaround:

Private Sub cbJobField_Change()
cbJobField.DropDown
Sheets("Links").Range("DropDownOpen").Value = "True"
End Sub

Private Sub cbJobField_KeyDown(ByVal KeyCode As MSForms.ReturnInteger)
If KeyCode = vbKeyReturn Then
If Sheets("Links").Range("DropDownOpen").Value = "True" Then
Sheets("Links").Range("DropDownOpen").Value = "False"
ActivateComboBox cbJobField
Else
btnFind_Click
End If
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top