keyPress event and combobox!

  • Thread starter Thread starter riccifs
  • Start date Start date
R

riccifs

Does anyone to known how to code a combo box so that when I start to
type something, it drops down its list of items?
At moment I'm using that code;

Private Sub Form_KeyPress(KeyAscii As Integer)
Dim ctlCurrentControl As Control
Dim lngType As Long
Set ctlCurrentControl = Screen.ActiveControl
lngType = ctlCurrentControl.Properties("ControlType")
If lngType = 111 Then 'Combo Box (see the Object Browser)
If KeyAscii > 32 Then
Screen.ActiveControl.Dropdown
End If
End If
Set ctlCurrentControl = Nothing
End Sub

It seems to work but recently I discovered a bug in it.
If I click on the record selectors (the one on the extreme left side
of the form) and after hit the Esc key, I got error on this part of
the code "Set ctlCurrentControl = Screen.ActiveControl" telling me
"the expression you entered requires the control to be in the active
window".

Who knows how to help me?
Many thanks...
Stefano.
 
Why don't you use the Change event of the combo?

Me.ComboName.DropDown

Hi Arvin,
you're right! It was so simply... anywhere many thanks for your help!
Now it works great.
Bye,
Stefano.
 
Back
Top