Getting single selected record from multiselect listbox

  • Thread starter Thread starter Max Moor
  • Start date Start date
M

Max Moor

Hi All,

I have a multi select listbox that I use both as a single select and a
multi select. I can't change the multi select property in VB, so I keep a
software switch of my own, and trap the click event.

When getting multiple selected records, I use the standard, Access help
code:
For Each varItem In ctlItemList.ItemsSelected
Debug.Print ctlItemList.ItemData(varItem)
Next varItm

What I'm wondering is if there isn't a shorthand, maybe using the
ItemsSelected property, for getting row data when I know only one record is
selected? The code above would work, and just iterate once, but it seems a
lot of code to type to get one records data.

Thanks,
Max
 
Max,
when it is in single select, do the same as with a combo box.
Use Me.ListBoxControlName to get the selected value, assuming you want the
ID from the hidden column.

Jeanette Cunningham
 
Hi All,

I have a multi select listbox that I use both as a single
select and a
multi select. I can't change the multi select property in VB, so
I keep a software switch of my own, and trap the click event.

When getting multiple selected records, I use the
standard, Access help
code:
For Each varItem In ctlItemList.ItemsSelected
Debug.Print ctlItemList.ItemData(varItem)
Next varItm

What I'm wondering is if there isn't a shorthand, maybe
using the
ItemsSelected property, for getting row data when I know only one
record is selected? The code above would work, and just iterate
once, but it seems a lot of code to type to get one records data.

Thanks,
Max
Why type when you can copy and paste?

Better yet, why not restructure your logic to use the same code.?
It's not difficult to do.
 
Max,
when it is in single select, do the same as with a combo box.
Use Me.ListBoxControlName to get the selected value, assuming you want the
ID from the hidden column.

Jeanette Cunningham

Hi Jeanette,
I would, but when it's in single select, it's really still in
multiselect. The multiselect property can't be changed from VB, so as far as
access is concerned, it in multi-mode all the time. Given that, the bound
column always returns null with that syntax.
-Max
 
Back
Top