Listbox is Highlighted but not Selected (1 Viewer)

kpstrat35

Registered User.
Local time
Yesterday, 17:26
Joined
Aug 15, 2016
Messages
10
I have an unbound listbox on a subform. The Row Source is a table and it is filtered using the Criteria of one of the fields based on a textbox on the subform.

By clicking on a button on the subform, an item from a combobox on the subform is added to the table the Row Source of the listbox is based on. After the new record is added to the table, the listbox is requeried and the new record shows up in the listbox just fine at the bottom of the list using me.lstFlightLegs.Requery.

If I stop the code here, the item that was previously the last item (and was selected before) remains the selected item in the listbox. I want the new item to be the selected item.

My code:
'requeries the listbox to get the newly added item to the table to show up
Me.lstFlightLegs.Requery
'tries to select the newly added item - it does highlight the correct item but there is still a dashed box around the previously selected item
Me.lstFlightLegs.Selected(intLegNumber) = True
'I decided to try and requery the listbox again. But this is the really confusing part because when I do, the listbox selects the previously selected item
Me.lstFlightLegs.Requery

I did another test in the code. The visual of the listbox is deceptive. After the above code is run,
"lngID = Me.lstFlights" returns the value of the previously selected item
"strFlightLeg = Me.lstFlightLegs.Column(2)" returns the value in Column(2) of the newly added item.

Recap. A record is added to a table. The listbox is requeried which shows the new item. However, I can't figure out how to select the newly added item. .Selected = True only highlights but doesn't truly select the item.
 

kpstrat35

Registered User.
Local time
Yesterday, 17:26
Joined
Aug 15, 2016
Messages
10
After all that I realized I had the solution in another part of my code.

.Selected = True doesn't work but setting the listbox equal to the specific item's list index does work.

Me.lstFlightLegs = Me.lstFlightLegs.ItemData(intLegNumber)
 

Users who are viewing this thread

Top Bottom