Hello.
I can probably find a workaround for my particular problem by updating the record source for the form instead of just the listbox, but I'm betting there's a simple solution that I'm just not experienced enough to find.
- I've got an unbound listbox on a form that I use to direct-select navigate to records on the form.
- I also have form action buttons to control movement (next, previous, new, etc.)
- I have filters on the form that affect the records displayed in the listbox.
If I filter the unbound listbox, the navigation buttons naturally don't go from one filtered record to the next.
I adapted this code that I found (https://stackoverflow.com/questions/...ox-by-vba-code) for how to move to the NEXT record in a listbox by clicking the button, and the code almost works. It visually move the cursor to the NEXT record.
I then tried to execute the lstItem_AfterUpdate code to update the form.Code:Private Sub cmdListBoxNext_ClickWith me.lstItem if .ItemSelected.Count = 0 Then Exit Sub 'Can't move if nothing is selected Dim lngCurrentPosition As Long lngCurrentPosition = .ItemSelected(0) If lngCurrentPosition = .ListCount then Exit Sub 'Can't move further than the last item Debug.Print me.lstItem .Selected(lngCurrentPosition) = False 'Deselect current item .Selected(lngCurrentPosition +1) = True 'Select next itemDebug.Print me.lstItemEnd With
What's happening is that even with moving the cursor in the listbox (the form visually updates), the value of me.lstItem remains the same, as shown by the before and after debug.print outputs. In fact, no matter how many lines down the cursor moves, the value of lstItem stays constant.
I'm guessing there's a single piece of code I'm missing to actually update the control/Select the value of the line now represented in the listbox, I just cannot figure out what that is.
Thanks in advance for your help.