Move to next row in a listbox

H

HanSolo

BACKGROUND
I have a form where users filter incomplete records in the form via a
listbox. I'd like to create a command button that the user would press
after completing a record. This command button would refresh the
contents of the listbox to only show incomplete records (I've already
accomplished this, as such am not going to go into criteria details),
and then....

MEAT OF MY QUESTION
.....move to the next row in the listbox (this is where I'm having my
problem). Once the next row in the listbox is highlighted, I'm
assuming that my form would be filtered just as if I had manually
clicked the next row in the listbox.
 
W

Wayne Morgan

A couple of things, first the "next row" will probably be the first row
after you requery the listbox to remove the record you just completed, is
this correct? If not, how do you want to determine when to go to the next
row and when to go to the first row because the previous first row has been
finished and removed?

Next, I assume you are taking the filtering action in the listbox's
AfterUpdate event. This event will fire when you make your selection in the
listbox. Changing the value of the control using VBA does NOT cause this
event to fire; however, you can call it through VBA after you set the value.

To set the value of a single select listbox to the first row in the listbox
then call the listbox's AfterUpdate event:

If Me.lstMyListbox.ListCount > 0 Then
Me.lstMyListbox = Me.lstMyListbox.ItemData(1)
lstMyListbox_AfterUpdate
End If

The ItemData property is usually used with a multiselect listbox. However,
it still returns the value from the Bound Column of the specified row even
when the listbox is not set for multiselect. So, in the statement above, we
are setting the value of the listbox to the value of the Bound Column in the
first row.

If your listbox has a header row (column titles) you need to change the ">0"
to ">1" because the header row is counted by ListCount.
 
Top