Results 1 to 9 of 9
  1. #1
    hvcleon2000 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2014
    Posts
    4

    VBA,Access. How to selec item in listbox by pressing enter key


    Hi all Bro/Pro,

    I have a listbox with *Like* search function as attached file. However, when the cursor moves to select items in listbox, a specific item can not be selected by Key Press even (Enter key). I do not know what my mistake is . Please help. Thanks
    Attached Files Attached Files

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Don't know why you are using the Keypress code..

    Removed the Keypress code and added a button.
    Seems to work now....maybe not what you wanted??

  3. #3
    hvcleon2000 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2014
    Posts
    4
    Quote Originally Posted by ssanfu View Post
    Don't know why you are using the Keypress code..

    Removed the Keypress code and added a button.
    Seems to work now....maybe not what you wanted??
    Thanks for fast reply. However, button click is not my question. I want that after entering text in the Search Text Box, then, press Tab, the focus will move to the Listbox, then, I can select any item by pressing enter instead of clicking the button. The Bound Value will be returned in the Test Text Box

  4. #4
    razors1968 is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    18
    Hi

    does this do what you wanted?

    Private Sub List_HH_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    Me.Test.SetFocus
    Me.Test.Text = Me.List_HH.Value
    End If
    End Sub

    Ray

  5. #5
    hvcleon2000 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2014
    Posts
    4
    Quote Originally Posted by razors1968 View Post
    Hi

    does this do what you wanted?

    Private Sub List_HH_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    Me.Test.SetFocus
    Me.Test.Text = Me.List_HH.Value
    End If
    End Sub

    Ray
    Hi Mr. Ray,

    It doesnt work. Your code works only when I select an item on the list by press enter, then, I move the cursor out of this list to the Search_Textbox and press enter again. Then, the Bound Value appears on the Test Text Box. Please help again

    Thanks

  6. #6
    razors1968 is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    18
    hvcleon2000

    The process you want is
    1. Enter some text in the search text box (This filters the list box for rows that contain that text)
    2. Press Tab to get to the list box
    3. Use arrows keys to select the row you want
    4. Press enter and the bound column value of the selected row appears in the Test text box ?

    Is that the correct sequence?

  7. #7
    hvcleon2000 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2014
    Posts
    4
    Quote Originally Posted by razors1968 View Post
    hvcleon2000

    The process you want is
    1. Enter some text in the search text box (This filters the list box for rows that contain that text)
    2. Press Tab to get to the list box
    3. Use arrows keys to select the row you want
    4. Press enter and the bound column value of the selected row appears in the Test text box ?

    Is that the correct sequence?
    Yes. It is correct sequence (I am sorry for my english). Can you help me with this?

    Thanks a lot

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I've tried for about 45 minutes and can't get the ENTER key to enter a value into the test text box. I can get the PK to be entered if the space bar is used instead of the Enter key.

    Code:
     Private Sub List_HH_KeyPress(KeyAscii As Integer)
        If KeyAscii = 32 Then  '(32 = space key)
          Me.Test = Me.List_HH.Value
    '        Me![Toa_ChiTiet Subform].Form.MSHH = Me.List_HH.Value
        End If
    
    End Sub

    Double clicking on the list box seems easier.
    Code:
    Private Sub List_HH_DblClick(Cancel As Integer)
            Me.Test = Me.List_HH.Value
    '        Me![Toa_ChiTiet Subform].Form.MSHH = Me.List_HH.Value
    End Sub

    Sorry I couldn't help more....

  9. #9
    razors1968 is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    18

    Enter Key Behaviour

    Hi HVCleon

    This is curious. I have made the changes to the KeyPress event code and it works exactly as described in the sequence list. Just to be very clear

    1. Mouse pointer into the search box
    2. Type some text
    3. The list box filters for rows that contain the text in the search box
    4. Press the 'Tab' key
    5. Focus moves from search box to list box as this is the next control in the Tab Order Sequence
    6. None of the list items is selected until one of the arrow keys is pressed (If an arrow key is not pressed then the list box entry is not selected.)
    7. Arrow key up or down to the row you want ( I have added some code that selects the first item, this should mean that you do not necessarily have to press the arrow keys.)
    8. Press 'Enter' key
    9. Value of Bound Column appears in the test box.

    Please let me know if I have understood.

    Cheers

    Ray
    Attached Files Attached Files

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 17
    Last Post: 11-05-2013, 06:55 PM
  2. Set Focus to Next ListBox Item
    By burrina in forum Forms
    Replies: 2
    Last Post: 11-10-2012, 08:25 PM
  3. Automatic duplication of form when pressing ENTER
    By tanveerksingh in forum Forms
    Replies: 7
    Last Post: 08-15-2012, 10:03 AM
  4. Replies: 7
    Last Post: 06-05-2012, 03:22 PM
  5. Pressing the Enter key performs a task...
    By Fish218 in forum Forms
    Replies: 6
    Last Post: 03-06-2012, 02:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums