Get all combo boxes to drop down on arrow key with one piece of code

T

Tony

Hi All,

I've got a db with lots of combo boxes and I'd like the user to be able to
scroll through the list items using the up/down arrow keys. I'm currently
using the KeyPress event and looking for keycode = 40 to enable dropdown on
the combo box. However, this seems cumbersome as I have to do this on the
KeyPress event for every combo box in the db.

Can anyone offers suggestions as to how I can accomplish this globally as
opposed to adding code to each combo box's KeyPress?

Thanks & Ciao,

Tony
 
B

Brendan Reynolds

If you set the KeyPreview property of the form to 'Yes' in the Properties
window (or True if you set it in code) you can then do something like this
....

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = vbKeyDown Then
If Me.ActiveControl.ControlType = acComboBox Then
Me.ActiveControl.Dropdown
End If
End If

End Sub

BTW: Access already provides not one but two shortcuts to drop dow a combo
box - F4 and Alt+Down Arrow.
 
T

Tony

Hey Brendan,

Thanks for the response. I had no idea there was Form KeyDown event and
that looks promising for other 'global' things I want to accomplish. I was
aware of the other options to drop the box, but I want to make this as
simple as possible; I was instructed to 'design it so that our execs can use
it'. I'm sure you know how it goes...

Thanks & I'll post back to this thread if I have any further questions.

Ciao,

Tony
 

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