Listbox setfocus on row

G

Guest

I have a list box with a query from a table as the rowsource. Once a record
is selected and processed, it is removed from the table and the listbox
rowsource is refreshed. I would like the cursor(selection) to be placed on
the next record. I've tried the follwoing code (among many) without any
success. Any suggestions?

i = Me.lstItems.ListIndex
code to process record and remove from table... at end

Me.lstItems.Requery
Me.lstItems.ListIndex(i).SetFocus
The listbox has focus, but the cursor move to the first record on the page.
There is no sort option in the query.

Thanks
 
G

George Nicholson

Me.lstItems.SetFocus
Me.lstItems.ListIndex = i

Should select the i(th) item in the listbox.
If you don't SetFocus immediately before ListIndex, you will raise an error.

HTH,
 
B

banem2

I have a list box with a query from a table as the rowsource. Once a record
is selected and processed, it is removed from the table and the listbox
rowsource is refreshed. I would like the cursor(selection) to be placed on
the next record. I've tried the follwoing code (among many) without any
success. Any suggestions?

i = Me.lstItems.ListIndex
code to process record and remove from table... at end

Me.lstItems.Requery
Me.lstItems.ListIndex(i).SetFocus
The listbox has focus, but the cursor move to the first record on the page.
There is no sort option in the query.

Thanks

Hi,

Try this:

Dim i As Long
i = Me.lstItems.ListIndex
'Your code
Me.lstItems.Requery
Me.lstItems.ListIndex = i

Regards,
Branislav Mihaljev
 
G

Guest

Thank you very much for your response. It worked. All three solutions. This
has been a pain for a few months. Thanks again.
 
G

Guest

Thank you very much for your response. It worked. All three solutions. This
has been a pain for a few months. Thanks again.
 
G

Guest

Thank you very much for your response. It worked. All three solutions. This
has been a pain for a few months. Thanks again.
 

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