Open item from listbox when press Enter

crazybear

New member
Local time
Today, 12:15
Joined
Sep 19, 2010
Messages
2
I have a form with a listbox that displays the file names of files relevant to the record that are stored in a variety of locations.

I have successfully (and easily) managed in the doubleclick event to get it to open the file that is double clicked on.

However, in the interest of accessibility I also want to be able to use the up down arrows to select a file and then press Enter to open it.

Obviously the arrows work, as this is built in functionality, but I can't seem to get the selected item to open by pressing Enter... when I press Enter, the focus seems to move to the next control in the tab order.

I feel I may be having a "Friday Fried Brain" moment and that this is in fact relatively easy to do within, for example, the keypress event for the listbox ... but I just can't fathom it right now ... any help would be most welcome.

Bear.
 
First you will need to set the Form's Key Preview property to True (Yes).

Now in the Form's On Key Press event put the following code;
Code:
    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "YourFormNameToOpen"
    
    stLinkCriteria = "[YourRecordID]= " & Me![YourListBoxName]
    
    
    If KeyAscii = 13 Then
        DoCmd.OpenForm stDocName, , , stLinkCriteria
    End If
 

Users who are viewing this thread

Back
Top Bottom