Use 'enter' key to confirm combo box selection

fraser_lindsay

Access wannabe
Local time
Today, 16:59
Joined
Sep 7, 2005
Messages
218
Hi,


I have a simple form.
It has an unbound combo box.
I use the selection in the combo box and the after update event to filter my database records, by business.

When the form first loads it sets a default value and set focus to that combo control.

I want to be able to just press 'enter' to confirm that selection. How do I do it?

I have tried a number of different methods - experimenting with different events and adding a hidden control box, but I can't get it to work.

If I use the mouse to dropdown, then arrow cursors to navigate my list then press enter it selects what I want.

If I tab to a control button and select enter it activates the button.

Why can I not do this on my default selection in my combo box?

Thanks,

Fraser
 
The enter key is a very sticky subject. I've had occassions where the code works on some machines and some others it doesn't (mostly on a networked environment).

In any case this is how you would go about it. Ensure that the KeyPreview property under Event tab of the form is set to Yes. On the Key_Press event of the control do something like this:

Code:
    If Combobox1.ListIndex > -1 Then
        If KeyAscii = 13 Then
            ' Do something here. Maybe use a Msgbox to test that it works here.
        End If
    End If
 
why not have the combo box after update call a separate sub - then the form open event can just call that sub

eg

open event
....
set combo value
call combo sub
....


combo after update event
....
call combo sub
 

Users who are viewing this thread

Back
Top Bottom