?
Solved

How to Navigate with keyboard in a listbox after the rowsource is changed

Posted on 2012-09-02
11
Medium Priority
?
560 Views
Last Modified: 2012-09-04
Hello,

I have a listbox with 3 items for ex : Computers, lamps, Accessories.
when i click on one item, the list box rowsource change and become the sub category of the first list ex : For computer when i click the list become Screens, Hard drives, memories.

Everything works fine except that i want to use the keyboard to navigate between the list and when the form loads , the first list works fine (i may navigate with the arrows of my keybord or when selecting the first letter of the category) but when the second list is generated i may put the focus on the first item( with vba) but the keyboard is not more active before i click with my mouse on one item.

In fact i see on the first list by default a doted border around the black underground of the selected item, but not with the second list (until i click with my mouse).

How to solve the problem ?

Best regards
0
Comment
Question by:Ok123
  • 5
  • 3
  • 3
11 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 38358825
In addition to setting the focus, try using VBA to actually set the value of the list box to the first item in the list:

Me.lstBox = Me.lstBox.ItemData(0)


Doing this seem to allow the user to then use the arrow keys to select listbox values (I tested this in Access 2010).
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38358861
I'm thinking that you're using the OnClick event for your list box. Use the AfterUpdate event instead for your code and see if that works.
0
 

Author Comment

by:Ok123
ID: 38358877
Hi mbizup, IrogSinta,

Reply to mbizup : I do that but it's not working on access 2007

But you are right the code in attachement works with 2010 but not 2007.
Unfortunately, i need to find a solution for a 2007 environnement.

Private Sub Liste0_KeyDown(KeyCode As Integer, Shift As Integer)
    
    If KeyCode = vbKeyReturn Then
        Me.Liste0.RowSource = "'Screens';'Hard drives';'Memories'"
        Me.Liste0 = Me.Liste0.ItemData(0)

    End If    
End Sub

Open in new window



Reply to IrogSinta : i am using the keydown event because i don't want to use the mouse
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Expert Comment

by:IrogSinta
ID: 38359030
Ah, I misunderstood.  I thought you were referring to a second listbox and not the same listbox.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38359297
<<  works with 2010 but not 2007 >>

I just tested it with 2007, and am seeing the same results as you - and worse, I cant even tab out of the listbox.

It is possibly a 2007 bug that was fixed in 2010
0
 

Author Comment

by:Ok123
ID: 38359328
All my front end are in 2007 and i can't change it now ... it must have a solution ??
0
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 total points
ID: 38359342
Ha!  This seems to work for Access 2007...

Take the focus off of the listbox - to any other control you want -  before changing the rowsource, and then return the focus to the listbox after the rowsource has been changed,


Private Sub Liste0_KeyDown(KeyCode As Integer, Shift As Integer)
    
    If KeyCode = vbKeyReturn Then
        Me.cmdCommandButton.SetFocus  ' Set the focus anywhere other than the listbox
        Me.Liste0.RowSource = "'Screens';'Hard drives';'Memories'"
        Me.Liste0 = Me.Liste0.ItemData(0)
        Me.Liste0.SetFocus  ' Return the focus to the listbox

    End If    
End Sub

Open in new window

0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38359445
Miriam to the rescue again!!!
:-)
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38359487
:-)

You, btw, did a terrific job with that vba recordset question.
0
 

Author Closing Comment

by:Ok123
ID: 38361001
Hi mbizup ,

It's perfect !!!!

Many thanks for your solution.

A drink for you if we have a meet one day irl ;-)

Regards
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38364368
Glad to help out :)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question