keyPress event and combobox!

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.
 
A

Arvin Meyer [MVP]

Why don't you use the Change event of the combo?

Me.ComboName.DropDown
 
R

riccifs

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.
 

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

Top